Solved

preprocessors in visual studio

Posted on 2016-10-23
5
29 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 31

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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

914 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

18 Experts available now in Live!

Get 1:1 Help Now