Solved

Preprocessor definitions

Posted on 2015-02-08
4
138 Views
Last Modified: 2015-02-09
Hi

I have a visual studio projects that I am compiling in Debug mode with x64. However, I noticed that the Preprocessor definitions in Propert Pages->Configuration Properties -> C/C++ -> Preprocessor is WIN32.  Do I need to change this to 64 bit equivalent? What would that equivalent be? And what does this preprocessor definition mean anyway ?

thanks
0
Comment
Question by:LuckyLucks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 250 total points
ID: 40597172
WIN32 (ot _WIN32) is a predefined macro (see https://msdn.microsoft.com/en-us/library/vstudio/b0084kay%28v=vs.110%29.aspx - "Predefined Macros" - for a complete list) which MS explains as

_WIN32

Defined for applications for Win32 and Win64. Always defined.

There is also a _WIN64 but you usually don't need to explicitly set it, the compiler will do that when building x64 binaries.
0
 
LVL 34

Accepted Solution

by:
sarabande earned 250 total points
ID: 40598963
to add to before comment:

_WIN32 was used in various header files to enable or disable definitions for 32-bit winapi. it is mostly used to prevent non-windows or portable source code from including windows headers:

//crtdefs.h
...
#if     !defined(_WIN32)
#error ERROR: Only Win32 target supported!
#endif

Open in new window


another application of the macro is to suppress gui specifics for example when including a windows header by a console application (without _WIN32 defined):

//commctrl.h
...
#ifdef _WIN32

#if _WIN32_WINNT >= 0x0600
#define HBITMAP_CALLBACK               ((HBITMAP)-1)       // only for SparseImageList
#endif

WINCOMMCTRLAPI BOOL        WINAPI ImageList_Replace(__in HIMAGELIST himl, __in int i, __in HBITMAP hbmImage, __in_opt HBITMAP hbmMask);

WINCOMMCTRLAPI int         WINAPI ImageList_AddMasked(__in HIMAGELIST himl, __in HBITMAP hbmImage, __in COLORREF crMask);
WINCOMMCTRLAPI BOOL        WINAPI ImageList_DrawEx(__in HIMAGELIST himl, __in int i, __in HDC hdcDst, __in int x, __in int y, __in int dx, __in int dy, __in COLORREF rgbBk, __in COLORREF rgbFg, __in UINT fStyle);
#if (_WIN32_IE >= 0x0300)
WINCOMMCTRLAPI BOOL        WINAPI ImageList_DrawIndirect(__in IMAGELISTDRAWPARAMS* pimldp);
#endif
....

Open in new window


and there are also a few places where the _WIN32 is used to distuingish between 32-bit Windows and 16-bit Windows:

//
// Make sure FAR is defined...
//
#ifndef FAR
#ifdef _WIN32
#define FAR
#else
#define FAR _far
#endif
#endif

Open in new window


Sara







headers the #else branches often contain code for 16-bit windows, mac os, os/2
0
 

Author Comment

by:LuckyLucks
ID: 40599445
so just to clarify: the WIN32 preprocessor primarily distinguishes between windows OS and non-windows. It has nothing to  do with 32 or 64 bit windows OS.
0
 
LVL 34

Expert Comment

by:sarabande
ID: 40600074
so just to clarify: the WIN32 preprocessor primarily distinguishes between windows OS
no, most cases where _WIN32 was used is to distinguish between WIN32 projects and non-WIN32 projects, what means between projects using the win32 api or not. to the latter group belong all console programs which do not use winapi.

It has nothing to  do with 32 or 64 bit windows OS.
yes. 64-bit windows is a product of the last decade. the WIN32 macros are more than 40 years old and their main purpose was to distuingish between 16-bit windows and 32-bit windows and to suppress definitions only needed for winapi.

Sara
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question