Solved

preprocessor directive in C++

Posted on 2016-10-31
3
29 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 33

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

813 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

17 Experts available now in Live!

Get 1:1 Help Now