>How to identify if the given machine is 8/16/32 bit using C code ???
The "bitness" of a particular CPU is defined by the *MARKETING
DEPARTMENT* of the manufacturer of a particular CPU. In other
words, it can (and often is) a bunch of hooey.
There are more objective measures, like the size of CPU general
registers (if it HAS general registers), the size of the data bus,
the size of the address bus, etc. However, these tend to disagree
with each other.
For example, both the 8088 and the 8086 have 16-bit registers and
almost identical instruction sets. But the 8088 has an 8-bit
external data bus and the 8086 has a 16-bit external data bus. A
compiler for the 8086 probably works fine for the 8088. A compiler
for the 8086 probably works fine for the Pentium 4 in real mode:
the programming models are virtually identical. Let's see, is the
data bus 32 or 64 bits wide (or have memory bus widths gone to 128
by now?), or does it vary by specific model? And some models have
a *36* bit-wide address bus. Now, we've got an instruction set
(and compiler that generates code for it) that runs on 8, 16, 32,
or 64-bit hardware without having to know which it's running on.
Why is the bitness of the processor relevant again?
printf("Word length = %d", sizeof(int));
Doesn't that depend on the compiler you are using for compiling that
piece of code???
Yes. And it might even depend on command-line options given to
the compiler.
I think that there are compilers that use 4 bytes
for int irrespective of the underlying hardware ...
please correct me
if I am wrong :)
I consider that to be two different compilers if the instruction sets
are substantially different, even if a great deal of the code is
common between them.
Actually I think to check the bit ness of machine
... we need to check how much bit processor we are using ... and may
"how much bit processor we are using" is FUZZY IN THE EXTREME.
be that we can know if we know the size of the data bus or cpu
registers ... Am I right ??? ... then I suppose sizeof int may not
give compulsorily give the sizeof CPU register ... then how do we
check it using c code???
I think you're going to have a heck of a time checking it using
*ALL* the hardware and software manuals for the processor, the
complete chip design and masks, and all the employees of the
manufacturer that had anything to do with the design of the processor.
You'll *STILL* get arguments.
Gordon L. Burditt