Reputation: 1833
I read both /usr/include/bits/types.h
and /usr/include/sys/types.h
, but only see them use "unsigned int" or "signed int" to define some other relatively rarely used type for us, e.g:
typedef signed char __int8_t;
...
typedef signed int __int32_t;
or:
#define __S32_TYPE int
#define __U32_TYPE unsigned int;
As to "where is the signed int
(or int
) originally defined?" and "in which file, gcc decide the int
should be 4 bytes width in my x86-64 server"? I cannot find anything.
I am wondering the process in which the gcc/g++ compiler define these primitive type for us, and want to see the originally definition file. Please tell me the originally position or enlighten me about some method to find them.
Upvotes: 0
Views: 949
Reputation: 754090
The basic types are intrinsic to the compiler; they are built in when the compiler is compiled, and are not defined anywhere you can find it easily. (Somewhere in the code there is the relevant information, but it won't be particularly easy to find.)
Thus, you won't find the information in a header directly. You can get the size information from the sizeof()
operator. You can infer sizes from the macros in <limits.h>
and <float.h>
.
Upvotes: 0
Reputation: 779
int
, unsigned int
, long
and some others are system type, they are defined by compiler itself. Compiler has some demands on those type, for instance int
must be at least 16 bits, but compiler may make it longer. Usually int
means most efficient integral type of at least 16 bits.
You should not rely on actual size of int, if you need it to hold more than 32767, please stick to long
or long long
type. If you need certain amount of bits integral due to desired overflow behavior, you can use uint16_t
/uint32_t
types. If you want to make sure there is at least certain amount of bits, you can also use uint_fast16_t
/uint_fast32_t
.
Upvotes: 1