Is it possible to check the CPU architecture(is 64 or 32 bits) in a x86/x86-64 CPU without gathering information from the OS or some API, by means of low level code (C/C++ or assembly)?
One could check for the size of a pointer, like discussed here, but, from what I understand, this way lets you know the OS architecture is compiled for, because a 64 bit CPU running a 32 bit OS would report wrong results.
Maybe some cpuid
instruction or similar could do the trick but I couldn't find anything that fully satisfies these requirements. If you think it's not possible, I would appreciate a good reason to justify this (this may be a less objective answer). If you are wondering, this is for a CPU detection software.
Edit: In Determine 32/64 bit architecture in assembly, OP does not get some specific answer that explain how to do it, just that you should use cpuid, and links to How do you detect the CPU architecture type during run-time with GCC and inline asm?, that shows a good answer to me, but it isn't as complete as the answer that I marked as accepted, because Remy Lebeau gives a detailed explanation and tells which specific cpuid bit must be queried, instead of just writing some code, and I find it more appropiate for my question, because it is explained at a higher level scope(I never mentioned gcc, the second post does)