Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the meaning of `_t` of `size_t` in C? [duplicate]

Possible Duplicate:
What does a type followed by _t (underscore-t) represent?

I know what the size_t is. It's an integer type depends on platform. But I cannot figure out what the t stand for. And there are many typed which suffixes with _t. What's the _t means?

like image 480
eonil Avatar asked Feb 04 '11 10:02

eonil


People also ask

What does the T in Size_t mean?

"t" means "type" (or to some people, typedef , which is the command used to create them). size_t is the type used to specify memory sizes. time_t on the other hand, is the type used to specify time spans.

Where is size t defined?

size_t is a base unsigned integer memsize-type defined in the standard library of C/C++ languages. This type is described in the header file stddef. h for C and in the file cstddef for C++. Types defined by the header file stddef.

What is the size of Size_t in C?

size_t type is a base unsigned integer type of C/C++ language. It is the type of the result returned by sizeof operator. The type's size is chosen so that it can store the maximum size of a theoretically possible array of any type. On a 32-bit system size_t will take 32 bits, on a 64-bit one 64 bits.

What is Size_t data type in C?

The datatype size_t is unsigned integral type. It represents the size of any object in bytes and returned by sizeof operator. It is used for array indexing and counting. It can never be negative. The return type of strcspn, strlen functions is size_t.


2 Answers

"t" means "type" (or to some people, typedef, which is the command used to create them). size_t is the type used to specify memory sizes. time_t on the other hand, is the type used to specify time spans. They generally happen to refer to the same underlying type (a 64-bit or 32-bit integer, depending on the platform), but the label helps keep them straight conceptually so that the implementation details can be hammered out by the compiler.

For example, time_t used to be a 32-bit integer, meaning that the clock would roll over in 2038. But on most 64-bit architectures, they've expanded time_t to be a 64-bit integer, which means that 64-bit systems won't have a "year-2038" problem. Since code that deals with unix timestamps uses the type name time_t rather than int to refer to these values, everything will "just work" when you simply recompile the code for your new architecture.

like image 181
tylerl Avatar answered Oct 20 '22 17:10

tylerl


In my experience the _t is a conventional suffix for types declared using typedef.

e.g.

typedef int myInt_t;

etc...

like image 10
badgerr Avatar answered Oct 20 '22 16:10

badgerr