broeisi a écrit :
Hello,
Is there a way in C to get information at runtime if a processor is 32
or 64 bit?
Cheers,
Broeisi
Tbe processor in the machine that I use to write this message
can transform itself from
o 16 bit processor (at startup)
o 32 bit processor (If I boot into Windows XP or linux 32)
o 64 bit processor (If I boot into Vista 64 or linux 64)
All those systems use EXACTLY THE SAME HARDWARE!
If the processor runs under a 32 bit system there is NO
WAY (unless you use assembly) to know that processor can be
64 bits.
For x86 systems the only way to know the kind of processor
you are running on is to issue the CPUID assembly instruction.
lcc-win32 has an "intrinsic" function (called cpuid() )
that will return you a structure with several bit fields that
specify the type of processor, etc. But this must be done
in a machine specific way. Other processors may support different
instructions and return values for similar instructions.
But this can't be done at all from C. Actually C is designed
to ABSTRACT from those details and make your programs run the
same in different machines by emulating missing features. That is why
you can use 64 bit integers (or even 128 ones) in a 32 bit system.
C will emulate the missing functionality for you, masking the
differences in hardware. This makes programs written in C portable
from a machine to the next.