The meaning of known data types

Possible duplicate:
What does the type followed by _t (underscore-t) mean?

Does anyone know what "t" means in time_t, uint8_t, etc, is it "type"? secondly, why declare such types of new types, for example size_t, could it not be just an int?

+3


source to share


3 answers


Yes, t is for type.

The reason for defining new types is that they may change in the future. Since 64-bit machines have become the norm, it is possible for implementations to change the bit-width size_t

to 64 bits rather than 32. This is the way forward for your future programs. Some small embedded processors handle 16-bit numbers well. They size_t

can only be 16 bits wide.

It can be especially important to ptrdiff_t

represent the difference between the two pointers. If the pointer size changes (say to 64 or 128 bits) in the future, your program shouldn't care.



Another reason for typedefs is stylistic. Although these size_t can be simply defined

typedef int size_t;

      

using the name size_t

makes it clear that the variable means the size of something (container, memory area, etc., etc.).

+10


source


I think it means a type - a type that is possibly a typedef of another type. So when we see int

, we can assume that it is not a typedef of any type, but when we see it uint32_t

, it is most likely a typedef of some type. This is not a rule, but my observation, although there is one exception: is wchar_t

not a typedef of any other type, but it does _t

.



+1


source


Yes, it probably means type

either typedef

, or something like that.

The idea in between typedef

is that you are specifying that this variable is not shared int

, but it is the size of the object / number of seconds since UNIX / whatever; In addition, the standard provides specific guarantees regarding the characteristics of these types.

For example, it is size_t

guaranteed to contain the size of the largest object you can create in C, and the type that can do this can change depending on the platform (on Win32 this is unsigned long

fine, on Win64 you are required unsigned long long

, and on some microcontrollers with really small memory it can be unsigned short

).

As for the different ones [u]intNN_t

, they are fixed-size integer types: while for "plain" int

/ short

/ long

/ ... the standard does not require a specific size, you will need a type that, when you compile your program, is guaranteed to have a specific size (for example, if you read binary file); those typedef

are the solution to this need. (By the way, there are also typedef

for "fastest integer at least small size" when you need a minimum guaranteed range.)

+1


source







All Articles