Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to check whether you are building for 64-bit with Microsoft C Compiler?

Is there a simple preprocessor macro that is defined for a 64-bit build? I thought _WIN64 might have been it, but even when I build a 32-bit target, the parts enclosed in a #ifdef _WIN64 ... #endif are compiled in, and this is causing problems. It's Friday and I can't think straight, but I'm sure I'm overlooking something very simple here. Maybe even something involving sizeof.

like image 945
dreamlax Avatar asked Oct 30 '09 03:10

dreamlax


People also ask

How can I tell if Visual Studio is 32-bit or 64-bit?

The easiest way, without installing another program or running the file, is just to right click on the file, choose Properties, and then go the the Compatibility tab.

How do I change my Visual Studio application from 32-bit to 64-bit?

From the BUILD menu in Visual Studio, select Configuration Manager. From the Active solution platform drop-down list, select New. The New Solution Platform dialog displays. In the Type or select new platform combination box, select x64.

What is 64-bit compiler?

After you convert your 32-bit driver source code to use the new data types, you can use the 64-bit compiler to identify any type-related problems that you initially missed. The first time you compile this code for 64-bit Windows, the compiler might generate many pointer-truncation or type-mismatch warnings.

Is there a built in C compiler in Windows?

Unfortunately, there is no in-built compiler. You need to install one.


1 Answers

I have always used _WIN64 to check if it is a 64 bit build.

N.B. _WIN32 is also always (automatically) defined by MSVC in 64 bit builds, so check for _WIN64 before you check for _WIN32:

#if defined( _WIN64 )

// Windows 64 bit code here

#elif defined( _WIN32 )

// Windows 32 bit code here

#else

// Non-Windows code here

#endif
like image 184
Bruce Ikin Avatar answered Oct 14 '22 16:10

Bruce Ikin