Solved

preprocessors in visual studio

Posted on 2016-10-23
5
24 Views
Last Modified: 2016-11-12
Hi


This is in context to visual studio and C++ questions. I notice that there are a few preprocessor definitions such as WIN32 , _WINDOWS etc in the Preprocessor section under C/C++.Is there somewhere else that more of these preprocessor definitions could be coming from? For example, in the code i see a check for WINAPI. If it is not listed here in the preprocessor definition, does it mean that it does not exist?

thanks
0
Comment
Question by:LuckyLucks
5 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 251 total points (awarded by participants)
ID: 41856064
Others, such as WINAPI are defined in Windows headers files.
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 83 total points (awarded by participants)
ID: 41856065
You can use #define (and related ones ) to create or remove things that the compiler can use when building the code.

https://msdn.microsoft.com/en-us/library/teas0593.aspx
http://www.cplusplus.com/doc/tutorial/preprocessor/
0
 
LVL 30

Assisted Solution

by:Zoppo
Zoppo earned 83 total points (awarded by participants)
ID: 41856083
In Visual Studio you can use the built-in code browser to find those macros, i.e. right-click the word WINAPI and select Go To Definition ... from context menue, this fills the output with the found location (or a list of locations if multiple were found) where this symbol is defined.
0
 
LVL 32

Assisted Solution

by:sarabande
sarabande earned 83 total points (awarded by participants)
ID: 41857396
If it is not listed here in the preprocessor definition, does it mean that it does not exist?
no, as told by evilrix the macros are defined in header files and for  a non-trivial application you may have hundreds if not thousands of macros defined in header files, especially if you were using many c libraries and c headers. in c++ many macros could be replaced by other means, for example by templates. then the compiler would do the replacements and switches and not the precompiler.

the macros in the c/c++ preprocessor section are macros which are default for the whole project configuration rather than for some source files. for example the _DEBUG and DEBUG macro would be defined for debug builds. or, for a dll project you would define a unique macro what could be used in source code that the dll functions and dll classes were exported by the project. projects that want to use the dll would not define this macro and so they would import the functions and classes from the dll.

note, some configuration settings will also add macros which you don't see in the preprocessor section. for example if you decide for to using 'UNICODE' character set (more accurate: wide characters from UTF16) rather than 'Multi-byte', the visual c++ compiler will define UNICODE and _UNICODE macro. this macro would make all MS strings to be wide character strings (that normally works quite ok if you never try to make a change).  

in the code i see a check for WINAPI
WINAPI resolves to __stdcall (what rules how a function call was handling stack and arguments when being called). WINAPI is a constant (which never was changed and never must be changed). so actually sources would not 'check' on WINAPI but use WINAPI as a specifier if they want define functions with a __stdcall interface rather than with __cdecl what is default.

Sara
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41884549
I think all are relevant information
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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.

747 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

10 Experts available now in Live!

Get 1:1 Help Now