Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Preprocessor definitions

Posted on 2015-02-08
4
Medium Priority
?
148 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 1000 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 35

Accepted Solution

by:
sarabande earned 1000 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 35

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

Industry Leaders: 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

715 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