How do I determine the word size of my CPU? If I understand correct an int
should be one word right? I'm not sure if I am correct.
So should just printing sizeof(int)
would be enough to determine the word size of my processor?
That being said, on Windows with Intel processors, the nominal word size will be either 32 or 64 bits and you can easily figure this out: if your program is compiled for 32-bits, then the nominal word size is 32-bits. if you have compiled a 64-bit program then then the nominal word size is 64-bits.
In the x86 PC (Intel, AMD, etc.), although the architecture has long supported 32-bit and 64-bit registers, its native word size stems back to its 16-bit origins, and a "single" word is 16 bits.
DWORD (32 bits/4 bytes) QWORD (64 bits/8 bytes)
Answer: The Pentium/Pentium Pro provide four data types: a byte (8 bits), a word (16 bits), a doubleword (32 bits), and a quadword (64 bits).
Your assumption about sizeof(int) is untrue; see this.
Since you must know the processor, OS and compiler at compilation time, the word size can be inferred using predefined architecture/OS/compiler macros provided by the compiler.
However while on simpler and most RISC processors, word size, bus width, register size and memory organisation are often consistently one value, this may not be true to more complex CISC and DSP architectures with various sizes for floating point registers, accumulators, bus width, cache width, general purpose registers etc.
Of course it begs the question why you might need to know this? Generally you would use the type appropriate to the application, and trust the compiler to provide any optimisation. If optimisation is what you think you need this information for, then you would probably be better off using the C99 'fast' types. If you need to optimise a specific algorithm, implement it for a number of types and profile it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With