Windows 10: See if System Type is 32-bit (x86) or 64-bit (x64) Windows 10
4 stars based on
Join Stack Overflow to learn, share knowledge, and build your career. Is there anyway from a C prog to find whether the OS is currently running in how to find 32 bit and 64 bit machine or 64bit mode. I how to find 32 bit and 64 bit machine using a simple program as below. Is this a correct approach? Would this code work in all the scenarios like, If the hardware is 64bit and the OS is 32bit what would it return?
I don't have machine to test this in diff configurations. In general, a 32 bits executable won't be able to tell if it is running under a 64 bit OS or a 32 bit one some OS could have a way to tell, I know of none but I haven't searcheda 64 bit executable won't run under a 32 bit OS if you discount the possibility for the 32 bits OS to emulate a processor running a 64 bits OS This would work in any situation where glibc is correctly configured, and would print your register size to stdout, or return an exit code of 1 otherwise.
In addition to compile-time methods, and if you are running on Windows: It will return either "x86" when a program is running in 32 bit mode either because it is running under a 32 bit OS or because it is running on a 64 bit OS but as a 32 bit program under WOW64 or either "IA64"or "AMD64" if running as native 64 bit program on a 64 bit OS.
I think your solution is probably valid in most common cases; certainly in all standard IA64 data models pointers are 64bit. This may not however be true of all architectures in theory. Since 32bit and 64bit compilation requires either a different compiler or a different compiler switch, the target architecture must be known at build-time, and need not be determined at run-time.
Email Sign Up or sign in with Google. Thanks for the advice. This tells you what the code was compiled for, it doesn't tell you the capabilities of the CPU. But 32bit code will be running in 32bit mode, so I guess that's all you need to know. What do you want to know really? I faced this questions when i was jus curious to explore what we could do from C. But i am expecting this would be needed, when i want to know whether the underlying architecture which my program is running is 32bit or 64bit.
Sizeof is a compile time constant In general a 32 bit executable won't be able to load a 64 bit library even under a 64 bit OS; libraries and executables need to be compiled under the same -- or at least compatible -- assumptions. I don't know if other architectures have anything analogous.
TMN, my understanding is that prabodh want to know what the OS support To answer your question how to find 32 bit and 64 bit machine as given: Everybody's all " sizeof is a compile time constant. Yes, but if the flux capacitor has 20 valence electrons in a vacuum Mackey May 3 at Andrew O'Reilly 1, 10 Yes; that is exactly what I said, and was kind of my point; you compile for a target, so the information is known at compile time. Duly noted, I have removed the example; now an exercise for the reader!
The only way to answer this question is either: AnT k 31 Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Stack Overflow for Teams is Now Available.