Solved

Preprocessor definitions

Posted on 2015-02-08
4
122 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
  • 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 33

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 33

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

830 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