Now I\'m talking about new type definition by a programmer using typedef keyword. As long as my pupils are used to the type size_t (for example by using function length ()),
As others wrote, you probably can find it if you search all the include files. However the fact that this is how most implementations work is not guaranteed.
The standard says that, for example, #include <stddef.h>
should provide a definition for size_t
which must be an unsigned integer type. But it also says that there's no need for a file called stddef.h to exist anywhere on the file system. And even an implementation that does provide such a file but that file only contains the following line
#pragma stdlib_stddef_h
would be perfectly conforming if the above pragma effectively provides what the standard prescribes for that header.
In other words, size_t is an unsigned integer type because that's what the standard says, not because that's what you can read in a header file.
std::size_t
is defined in <cstddef>
. See http://en.cppreference.com/w/cpp/header/cstddef.
You can try to expand standard include files with the C preprocessor (cpp
) by hand and check the output of that:
$ echo '#include <stdlib.h>' | cpp -I/usr/include - > stdlib-expanded.c
You will find that the output of cpp
even includes markers to indicate from which files the code in stdlib-expanded.c
has been included.
gcc provides some of the headers and that is relevant here: size_t
is defined in stddef.h
which is one of those headers. Here it is for instance at /usr/lib/x86_64-redhat-linux/4.1.1/include/stddef.h
. There the definition of size_t
is
typedef __SIZE_TYPE__ size_t;
__SIZE_TYPE__
is a compiler predefined macro (which allows to ensure that the compiler and the header agree and, as what the compiler expect depend on its arguments -- for instance with -m32 it is an unsigned 32 bit bits, and with -m64 an unsigned 64 bits types --, to have the header independent of the compiler arguments).
Just for completeness, have you considered simply asking C++ about size_t
?
#include <iostream>
#include <cstddef>
#include <limits>
int main()
{
std::cout << "sizeof(size_t) = " << sizeof(std::size_t) << std::endl;
std::cout << "is size_t an integer? " <<
(std::numeric_limits<std::size_t>::is_integer ? "yes" : "no")
<< std::endl;
std::cout << "is size_t signed? " <<
(std::numeric_limits<std::size_t>::is_signed ? "yes" : "no")
<< std::endl;
}
gives me
sizeof(size_t) = 8
is size_t an integer? yes
is size_t signed? no