Hi all,
I'm teaching C++. 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 funciton length ()), for which I had to ask them a little effort to just "believe" it is an integer type, I think it woud be great to show noew them where this type is defined.
So, I've done a lot grep's in /usr/include in an ubuntu box, and what I see is that size_t is, in turn, a redefinition of size_type wich in turn is a redefinition of metadata_type, and that's the end in this directory. Not found the final "typedef unsigned int metadata_type;".
In /usr/src I've found anohter previous type called yy_size_t,...
But, in any case I've been unable the get to the end of the chain.
Does anyone know where to find out the final definition to check out that it is an unsigned int (or the like)?
May be I miss a development package in my box? In this case, why I'm able to compile programs using size_t type?
std::size_t is defined in <cstddef>, as required by C++ standard.
*How* it is defined, depends on the compiler:
Here, I'll look at a few:
gcc: <cstddef> has the line "using ::size_t;" which pulls in C's size_t, defined in <stddef.h>
gcc's stddef.h does typedef __SIZE_TYPE__ size_t;, where __SIZE_TYPE__ is a macro constant defined with #define __SIZE_TYPE__ long unsigned int
xlc: <cstddef> also has the line using ::size_t;, and <stddef.h> simply has typedefunsignedlong size_t;
acc: <cstddef> also has the line using ::size_t;, and <stddef.h> has #include <sys/_size_t.h> , which says typedefunsignedlong size_t;
Humm, I don't know if explaining this in my classroom. It's an primary level and I guess I'm going to be forced to explain too much things, with the result opposite to intended.
For instance, someone could ask if, in the case of gcc, it's needed the macro __SIZE_TYPE__. (or, based on my experience as a developer, it's just something needed at certain moment in time, and later on it happens to be more painful changing it back than to keep it as is).
Anyway it's me who has learned a bit more about the setting up of this "mess" ;)