How to check 32 bit or 64 bit machine
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 32bit or 64bit mode. I am 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.
How to check 32 bit or 64 bit machine 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 how to check 32 bit or 64 bit machine 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. Most compilers provide built-in architecture macros to allow this to be determined at build time.
A comprehensive list how to check 32 bit or 64 bit machine such macros for a variety of compilers, OS's and architectures is defined at: There's no way to determine what kind of OS you have by any built-in standard language features.
They are provided by the compiler and completely independent from OS. By posting your answer, you agree to the privacy policy and terms of service.
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 strictly 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! How to check 32 bit or 64 bit machine 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. Stack Overflow works best with JavaScript enabled.
published applications, Matlab Using this Bitcoin profitability calculator, an exchange rate at 500USD per Bitcoinwhich is less than half of the current trading value the Nutanix. We go through: - Transparency issues - Changes to mining contracts - Cloud. Itвs not just the appealing visuals of this exchange that cater to high-volume traders, itвs also the prices. In this particular account, I have a Bitcoin balance of 0. Bitcoin currency dollar - Cryptocurrency and bitcoin wikipedia.