You are here:

C++/Macro Expension


i am trying to debug an application that has used complex macros.
can u suggest me a way to look at "Expanded MACRO Code"
i.e, code generated by preprocessor.
Thanks in advance

Yes I can. In fact I had to do just the same thing recently.

Look at the options for your compiler. If you are lucky there will be one to allow the output of the pre-processed source file - that is with all files included, all conditional compilation sections selected and, most importantly, all macros expanded. Note that generally all comments would also be stripped from the source by this point as well.

For example MS Visual C++ has the /P pre-process to file option. It can be set in Visual Studio in project properties under C/C++ / Preprocessor / Generate Preprocessed File (or similar) - I am doing this in Visual Studio 2005 as it is to hand so other versions may vary slightly. For MSVC++ 6.0 (and earlier?) you may have to add the /P option explicitly.

The GNU compilers (g++, gcc etc.) have the -E Preprocess only; do not compile, assemble or link option. This option may be common to some other compilers such as those from HP, Sun, Comeau etc. Note that the popular MinGW compiler for MS Windows is a port of the GNU compiler; it is also the compiler used with the Dev-C++ integrated development environment, so these should hopefully also support the -E option.

These are the compilers I have to hand or have had time to pop onto the WWW to check out their documentation. If this does not cover your compiler then if you use the command line ask the compiler command for help, or check out the documentation for the product. If you are on a UNIX or similar system try reading the man page for the compiler.  


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at


©2016 All rights reserved.