Size_t, key_t, time_t etc.

I have encountered these types of "X_t" many times in c programs, what do they actually mean? Where is the location of this definition?

+4
source share
2 answers

The suffix _t means "type"; this is not a rule that you should use, it is just a convention, followed by many standard types from standard libraries. They are usually defined in the header files that use them, or sometimes in the header files included by these headers.

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

If you want to know exactly which header file received the definition, you can start the preprocessor:

 gcc -E file.c -o file.i 

The output of file.i preprocessor will show you all file.i include files. Then you can find it for definition, then scroll up until you find a comment that indicates which header file it came from.

+16
source

I just did a google search using "c size_t" which gave this first link. time_t is also located on this site. Once you get this information, this is a small step to understand that key_t must follow the same pattern.

0
source

All Articles