Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preprocessor in visual studio 2010-c++ project

In .cpp file I use a macro mmData1.I searched in the project and see that this macro is defined in several files.(I.e. there are several .h files which have the line #define mmData1)

I want to know if there is a capability in VS10 to check from which file the preprocessor takes the macro value

like image 629
Yakov Avatar asked Jul 30 '12 21:07

Yakov


People also ask

How do I set preprocessor definitions in Visual Studio?

Select the Configuration Properties > C/C++ > Preprocessor property page. Open the drop-down menu of the Preprocessor Definitions property and choose Edit. In the Preprocessor Definitions dialog box, add, modify, or delete one or more definitions, one per line. Choose OK to save your changes.

How to add compiler options in Visual Studio?

In Visual Studio You can set compiler options for each project in its Visual Studio Property Pages dialog box. In the left pane, select Configuration Properties, C/C++ and then choose the compiler option category.

What is_ MSc_ ver?

Show activity on this post. _MSC_VER is (and always should be) defined when compiling with the Microsoft compiler so that it "evaluates to the major and minor number components of the compiler's version number".


1 Answers

If Intellisense does not know then there is no direct way. However, there are indirect ways. Say your macro name is SOME_MACRO

  1. After each instance of #define SOME_MACRO put #error Defined here, then right click the source file and choose Compile. If compiler returns an error remove the directive that raises it and compile again. The last instance of this error will tail the definition visible in the source.

  2. Make each directive defining SOME_MACRO define it as something else and then, in the source file, add these lines after all includes:

    #define STRINGIZE(x) STRINGIZE2(x)
    #define STRINGIZE2(x) #x
    #pragma message("SOME_MACRO is expanded as: " STRINGIZE(SOME_MACRO))
    

    Compile the source file; you should see the value in the build log.

  3. Less intrusive way: put those lines after each #define SOME_MACRO

    #pragma push_macro("STRINGIZE")
    #pragma push_macro("STRINGIZE2")
    #define STRINGIZE(x) STRINGIZE2(x)
    #define STRINGIZE2(x) #x
    #pragma message("Defining at " __FILE__ ":" STRINGIZE(__LINE__))
    #pragma pop_macro("STRINGIZE")
    #pragma pop_macro("STRINGIZE2")
    

    Or, if you don't need the line number:

    #pragma message("Defining at " __FILE__)
    

    Compile the file. Looking at build log you should be able to tell the order of SOME_MACRO definitions.

like image 76
gwiazdorrr Avatar answered Oct 06 '22 00:10

gwiazdorrr