tags:

views:

336

answers:

2

i have encountered these "X_t" types many times in c programs,what does they really mean?where is the location of these definition?

+11  A: 

The _t suffix means "type"; it's not a rule that you have to use it, it's just a convention followed by a lot of standard types from the standard libraries. They're usually defined in the header files that use them, or sometimes in header files included by those headers.

size_t is defined in <stddef.h>, and time_t is defined in <time.h>. key_t is not a standard C type, so it's probably defined in the library header for whatever library it's used in.

If you want to know exactly which header file a definition came from, you can run the preprocessor:

gcc -E file.c -o file.i

The preprocessor output file.i will show you all of the nested include files. You can then search it for the definition, then scroll upwards until you find the comment that indicates which header file it came from.

Adam Rosenfield
the preprocessor method for finding header files is really useful,thanks!I just wondering if "cpp" and "gcc -E ..." is the same?
yfel
"cpp" on a linux system generally invokes g++, which is not the same as gcc.
gnud
I think that the _t suffix is reserved by POSIX for future expansion. If that's really so then it's generally not a good idea to use _t as a suffix for user defined types.
Inshallah
A: 

I just did a Google search with "c size_t" which gave this first link. time_t information is on that site as well. Once you get that information, it's a small step to realize that key_t must be following the same pattern.

kajaco