0

Can anybody tell me how to

  1. Get all macros of a C++ project, or
  2. If above is impossible, check if a project contains some macro, say, MACRO_X?
  3. I am using Visual Studio Professional 2012 on Windows 7, so, preferrably, tools involve only those avialable in this environment.

Thanks in advance!

user4581301
  • 33,082
  • 7
  • 33
  • 54
leo
  • 357
  • 2
  • 15
  • Of course this is possible. The pre-processor in a C++ compiler does almost exactly this, except rather than notify you that the macro is there, they do the substitution. So all you need to do is write a pre-processor that notifies instead of substituting. – user4581301 Apr 10 '16 at 20:59
  • 1
    AFAIK in ObjectBrowser (https://msdn.microsoft.com/en-us/library/kbs280h1.aspx) you can browse macros too. You can also use command line tool :https://msdn.microsoft.com/en-us/library/87x7wc99.aspx But - I am not sure - I do not have visual studio installed... – PiotrNycz Apr 10 '16 at 21:11
  • You could set search scope to "Entire project" and search for "#define" – Logicrat Apr 10 '16 at 21:12
  • @Logicrat: That would miss all macros defined in 3rd party header files, or those defined on the command line. – IInspectable Apr 10 '16 at 22:44
  • See [this answer](https://stackoverflow.com/a/74592316/1147688). – not2qubit Nov 27 '22 at 19:21

2 Answers2

0

If you're using VS, I assume you're using this on Windows with the MSVC cl compiler, in which case you can get all C++ macros (from Developer Powershell) with:

echo // > foo.cpp; cl /nologo /Zc:preprocessor /PD /EHs /TP foo.cpp |sort; rm foo.cpp, foo.obj
not2qubit
  • 14,531
  • 8
  • 95
  • 135
-1

Try this (a starting point):

gcc -dM -E - < /dev/null >
/<pathFileName>/gcc_predefined_macros.txt

On an earlier version of my system, it produced 450+ items. I have not found a way to confirm.

g++ 5.2.1 on Ubuntu 15.10 reports 241 predefined macros ... I think most of the reduction is duplicate removal. I still have not found a mechanism to confirm.

But, I suppose this does not get user defined macros nor command line, either.

2785528
  • 5,438
  • 2
  • 18
  • 20