Solved

preprocessor directive in C++

Posted on 2016-10-31
3
16 Views
Last Modified: 2016-11-19
Hi

I have a project in Visual Studio with the following mentioned in preprocessor directive definitions , WIN32.

However,  in the code itself, i see checks using
#if defined (__WIN32)
 //do something
#endif

Why and what is this underscore? Would it be the same had i written it as a WIN32?
0
Comment
Question by:LuckyLucks
  • 2
3 Comments
 
LVL 32

Assisted Solution

by:sarabande
sarabande earned 250 total points (awarded by participants)
ID: 41867122
No, __WIN32 is different to _WIN32 and different to WIN32.

the purpose of the

#ifdef <MACRO_NAME>
...
#endif

Open in new window


is to add the enclosed statements only when the <MACRO_NAME> was defined before. the definition of a macro may happen either in the preprocessor definitions of the project, or in some code - almost ever in a header file, included before the #ifdef block.

i only found WIN32 in my sources and VC includes.

in the visual studio sdk, i also found _WIN32, in some internal windows headers. generally names with an underline prefix are reserved for internal use of the compiler or sdk. they shouldn't be user defined (although this was widely ignored in my experience).

__WIN32 (with two underlines) i didn't find anywhere.

Sara
0
 
LVL 28

Accepted Solution

by:
pepr earned 250 total points (awarded by participants)
ID: 41867365
It is likely that your project is cross-platform or (from another point of view) ready for a compiler other than Visual Studio. It means that the macro wraps the things for another compiler.

For the __WIN32, see the information at  C/C++ tip: How to detect the operating system type using compiler predefined macros that explicitly explains the meaning for the mentioned compilers (slightly below the half of the page).
0
 
LVL 28

Expert Comment

by:pepr
ID: 41894066
No comment. The questions should be closed ;)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now