Solved

preprocessor directive in C++

Posted on 2016-10-31
3
44 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
[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
3 Comments
 
LVL 34

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 29

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 29

Expert Comment

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

Featured Post

Independent Software Vendors: 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

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

717 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