Wednesday, April 11, 2012

How to View Preprocessor Output using Visual Studio

We know that preprocessing is the very first step for C/C++ program. In which all preprocessor statements are executed and final C/C++ file is prepared which is then given for syntax and semantic checking. But do we know how preprocessed output like? Here is the way to have look and clear your all doubts.

To set this compiler option in the Visual Studio development environment:

1. Go to Visual Studio Project's Property:
2. Expand Configuration Properties tab 
3. Expand C/C++ tab 
4. Click the Preprocessor 
5. Change Preprocess to a File to 'Yes' 
6. And now compile your program. VS will list down some errors, ignore those errors. 
7. Go to output directory and search for FileName.i  file. (FileName is name of the file for which preprocessed output is prepared)

OR  
You can use Visual Studio Command Prompt with following command:
D:\> CL /P /C FileName.c
 

This will generate FileName.i preprocessed output. This file is much more larger than the original if have included any standared header files like stdio.h etc.