Anyone know how to check if a machine is 16 bit, 32 bit etc?
I need to make my C++ program portable,
but I'm not sure what macro can I use to accomplish this
Name:
Anonymous2006-01-21 7:15
Check to see if the "long long" type is supported.
Name:
Anonymous2006-01-21 10:05
umm...I'm trying to do something like
#ifdef machine_is_32_bit
#else
#endif
any idea?
Name:
Anonymous2006-01-21 10:16
First tell me why you think you need to know if the machine is 16 bit or 32 bit, and then I'll tell you what you really want to do.
Name:
Anonymous2006-01-21 13:52
there are many reasons. such as adding DS_LOCALEDIT flag, selecting the best type for a template (i.e. 32 bit int for 32 bit machine) etc.
Name:
Anonymous2006-01-21 13:53
there are many reasons. such as adding DS_LOCALEDIT flag, selecting the best type for a template (i.e. 32 bit int for 32 bit machine) etc.
Name:
Anonymous2006-01-21 14:58
>> such as adding DS_LOCALEDIT flag
You're compiling for Windows? Then search the documentation Microsoft so kindly make available to you.
>> selecting the best type for a template (i.e. 32 bit int for 32 bit machine)
And are you aware of what the definition of int is?
Name:
Anonymous2006-01-21 15:19
How do I optimized prematurely.
Name:
Anonymous2006-01-21 17:59
isn't it something like: 8 * sizeof (int), or something? I could be wrong because I never rely on such values but...
Name:
Anonymous2006-01-24 4:30 (sage)
>>9
any up to date compiler would do something like that. you would probably see that kind of thing in bits of legacy code.
Who compiles code for 16-bit x86 these days anyhow, outside the embedded world? And in the embedded devices biz you rarely recycle code, let alone write in C++. (Can't predict what the compiler produces being the reason.)
>>13
But... wasn't everything even remotely interesting for DOS (i.e. like after 1993 or so) done in a 32-bit mode driver? DOS4GW comes to mind, though that was a bit later. I doubt that the ZSNES guys would go out of their way to support 16-bit DOS (i.e. 286-class things) given that it's a multiplatform project...
That's simply not possible standard-wise: it actually does not make any sense whatsoever.
In practice, however, sizeof(void*) can be used as a hint to detect whether you're compiling in a 32-bit or 64-bit environment, though it is useless as a preprocessor token.
CHAR_BIT and sizeof(void *) are the closest things C has to a concept of "bit width." All standard integer types must be supported on all C implementations and it's possible for a machine with e.g. 64-bit data registers to use a 16-bit int or for a machine to have 128-bit pointers and a 16-bit size_t.