How can I find out my system word size??Can anybody tell me "C" Program to find out word size??
Ex: if it 32 bit then should print 32-bit, if it is 64 bit should print 64-bit
How can I find out my system word size??Can anybody tell me "C" Program to find out word size??
Ex: if it 32 bit then should print 32-bit, if it is 64 bit should print 64-bit
should do itCode:#include <stdio.h> #include <limits.h> int main(void) { printf("%d\n", sizeof(void *) * CHAR_BIT); return 0; }
> How can I find out my system word size?
With great difficulty, if you're trying to do it in code.
Just take sl4nted's answer and compile it using TurboC on your nice new 32 or 64 bit machine, and you'll get obviously wrong answers.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Are you referring to an ancient version of 16 bit Turbo C running under a 32 bit windows, Salem, or something else? If you're referring to something else ...... more info please!
Assuming you have a native compiler (a compiler that specifically targets the type of system your application will run on), sl4nted's answer is a good starting point.
maybe cause I'm assuming an address is the size of a word. I'm also assuming CHAR_BIT is the amount of bits in a byte. which in my experiece are both fair assumptions. I'd like to know why these assumptions aren't correct.
But wouldn't sizeof(void*) tell you the size of a void pointer for this particular compiler, which has nothing to do with the processor the code would run on?Assuming you have a native compiler (a compiler that specifically targets the type of system your application will run on), sl4nted's answer is a good starting point.
When you compile code - you do it for target processor/OS - so it is modified for the specified target.Originally Posted by anon
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
yes, with my compiler (gcc) the size of a pointer is the size of an address, which in turn is more than likley the size of a word. atleast I thought till now
Yes, but if you put your current gcc on a 64 bit processor, then you're in the same boat as Turbo C.
There isn't a C function to tell you if your compiler is incompatible with your architecture.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
On a PURE 64 bit machine (ie, the OS is also 64bit) would not that code still work?
If you are on a 32 bit platform, then the size of the register to you is 32 bit, not 64, regardless of what plugins you have for the processor driver (ie, the AMD 64-bit drivers) -- unless you're using the libs from the processor mfg that allows you access to the extended registers.
Depends on compiler you use, Not?On a PURE 64 bit machine (ie, the OS is also 64bit) would not that code still work?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
OK; Salem's point is that, in C, the best you can hope for, without knowledge of your target machine, is information about the word size supported by your compiler. Since it is possible for a compiler to support one word size, and the programs it produces to run on an machine with different word size, it is not always possible to extract the word size for your machine. To extract the word size for your machine, you need to use machine or OS-specific methods (which implies you must have some idea about what type of machine your application will run on). If you have a compiler that supports the same word size as the target machine, then knowing word size supported by your compiler is sufficient.