Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I see what a file looks like after preprocessing?

How can I check the results of preprocessing? For example, say I have the following code:

#define CONCATENATE(X, Y) X ## Y
#define STRING_1 First
#define STRING_2 Second
#define STRING_3 CONCATENATE(STRING_1, STRING_2)

Is there a way to make sure STRING_3 will be expanded to FirstSecond later in the program?

like image 841
Maxpm Avatar asked Dec 22 '22 17:12

Maxpm


2 Answers

Each compiler should provide a switch to keep the preprocessed code

  • gcc: -E
  • MS Visual Studio: Keep preprocessed files in the settings or /P switch

For other compilers I bet you'll find a suitable switch in the documentation

like image 90
jdehaan Avatar answered Jan 08 '23 14:01

jdehaan


I think the best thing to do is run the C++ file under g++ -E <file> -o <file>.out and then check the result that way.

I assume you mean check it as in debug - obviously you can't check it at runtime as the preprocessor information won't exist.

like image 39
alternative Avatar answered Jan 08 '23 13:01

alternative