Solved

preprocessors in visual studio

Posted on 2016-10-23
5
60 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
[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
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 34

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

617 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