When compiled with GCC on Linux, the long of 32-bit machines is 4 bytes, and the long of 64-bit machines is 8 bytes.
I searched for the definition of macro INT_MAX on VS. It seems that there is only one place, which is 2147483647, so there should be no way to set it. I can only define a type myself.
And I learned that usually some projects do not use default types directly, but redefine a set of types for use. For example, I can define a set of types like this:
#ifdef m32
typedef int SpacelanInt;
typedef float SpacelanFloat;
#else
typedef long int SpacelanInt;
typedef double SpacelanFloat;
#endif
You cannot "set" the word length of int. This thing is not something that can be set in the first place.
But in most C implementations, the word length of long is equal to the machine word length, provided that you generate a "native binary", such as generating a 64-bit program in a 64-bit system.
In addition, the word length of pointer/intptr_t/uintptr_t is generally equal to the machine word length.
Of course, this is not the case on microcontrollers such as 51 or in ancient 16-bit systems
The data models used on different platforms (x86, x64, etc.) and different compilers are different. For details, please refer to: http://en.wikipedia.org/wiki/64-bit_computing# 64-bit_data_models
In addition, if you want to get a data structure with the same machine word length, you can use size_t
I can’t configure to generate 64-bit programs using VC 2010, but others have this option. But now that I think about it, this option is meaningless. Most people have 32-bit systems, even for the little bit of 64-bit. I guess the performance improvement is almost the same as 32-bit
Generally, the header files that come with the compiler include typedefs such as __int32, int32, int32_t, etc., which can ensure that it is 32-bit. However, if the code crosses the compiler, there will be problems, and you need to package it yourself.
When compiled with GCC on Linux, the long of 32-bit machines is 4 bytes, and the long of 64-bit machines is 8 bytes.
I searched for the definition of macro
INT_MAX
on VS. It seems that there is only one place, which is2147483647
, so there should be no way to set it. I can only define a type myself.And I learned that usually some projects do not use default types directly, but redefine a set of types for use. For example, I can define a set of types like this:
You cannot "set" the word length of
int
. This thing is not something that can be set in the first place.But in most C implementations, the word length of
long
is equal to the machine word length, provided that you generate a "native binary", such as generating a 64-bit program in a 64-bit system.In addition, the word length of pointer/
intptr_t
/uintptr_t
is generally equal to the machine word length.Of course, this is not the case on microcontrollers such as 51 or in ancient 16-bit systems
The data models used on different platforms (x86, x64, etc.) and different compilers are different. For details, please refer to:
http://en.wikipedia.org/wiki/64-bit_computing# 64-bit_data_models
In addition, if you want to get a data structure with the same machine word length, you can use size_t
I can’t configure to generate 64-bit programs using VC 2010, but others have this option. But now that I think about it, this option is meaningless. Most people have 32-bit systems, even for the little bit of 64-bit. I guess the performance improvement is almost the same as 32-bit
http://baike.baidu.com/item/int64
Generally, the header files that come with the compiler include typedefs such as __int32, int32, int32_t, etc., which can ensure that it is 32-bit. However, if the code crosses the compiler, there will be problems, and you need to package it yourself.
There is intptr_t in it