?
Solved

preprocessor directive in C++

Posted on 2016-10-31
3
Medium Priority
?
49 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 35

Assisted Solution

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

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…
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 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…
Suggested Courses

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