Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

size_t,key_t,time_t etc

Tags:

c

linux

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

like image 687
Pwn Avatar asked Dec 05 '22 05:12

Pwn


1 Answers

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.

like image 64
Adam Rosenfield Avatar answered Dec 07 '22 17:12

Adam Rosenfield