The size of an integer in C

Possible duplicate:
Does int size depend on compiler and / or processor?

Does the size of Integer depend on the compiler or OS or processor? What if I use gcc for both a 32-bit OS and a 64-bit OS that runs on either a 32-bit machine or a 64-bit machine (in this case, only a 64-bit OS is used).

+4
source share
6 answers

Depends on the compiler options.
Of course, this depends on the compiler itself.
But the compiler was created for a specific OS, so it depends on the OS
And / or
The compiler was created for a specific processor, so it depends on the processor

+3
source

It depends on the combination of compiler, processor and OS.

For example, on a 64-bit Intel processor in 64-bit mode, the long int size on Windows is 4 bytes, and on Linux and Mac it is 8 bytes. int - 4 bytes in all three operating systems on Intel.

The compiler developer also has a choice, but usually uses what the OS uses. But it is entirely possible that a compiler provider that has C compilers for all three platforms decides to use the same sizes in all three.

Of course, it makes no sense to do int 4 bytes (although that would be possible) on a 16-bit processor.

So it depends on all three things that you mention.

+5
source

The size is int, long, etc. depends on the compiler, but the compiler developer will choose the best size for a particular processor and / or OS.

+1
source

It depends on the system. And by the system, I mean any combination of the processor and the operating system, but usually it is tied to the "natural" integer size of the processor used.

0
source

The size of an int , and almost every other type, in C is determined by the implementation. Some compilers may provide guarantees on certain platforms, but this is implementation dependent. It's not worth relying on anything.

0
source

Is the size of Integer determined in the compiler or in the OS or on the processor?

Yes. It may depend on any of these things.

In fact, this is determined by the ABI platform, which is defined by the compiler and runtime libraries, but compilers use different ABIs for different OS or architectures.

0
source

All Articles