preprocessors in visual studio


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?

Who is Participating?
evilrixConnect With a Mentor Senior Software Engineer (Avast)Commented:
Others, such as WINAPI are defined in Windows headers files.
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
You can use #define (and related ones ) to create or remove things that the compiler can use when building the code.
ZoppoConnect With a Mentor Commented:
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.
sarabandeConnect With a Mentor Commented:
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.

AndyAinscowFreelance programmer / ConsultantCommented:
I think all are relevant information
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.