You are here:

C++/macro expansion

Advertisement


Question
hi,
I would like to know if you know any tool or compiler setting that produces precompiled source code file where macros are expanded.

i.e:
#define foo(a) if(a>0){return 0;}

int a=2;
foo(a)

will be expanded to

int a=2;
if(a>0){return 0;}

Regards,
Cem

PS: I am using Ms Visual C++ 6.0

Answer
Hello Cem, thank you for the question.

I'm not sure what you mean by "that produces precompiled source code file where macros are expanded."

From the sample code you have shown, it looks like what the compiler already does. A #define is nothing more than a precompiled text replacement. The compiler literally replaces the executed code on the current line with the code in the #define. It is nothing more than an implicit copy and paste as far as the compiler is concerned. If I'm missing something in the question please feel free to question me again.

I hope this information was helpful.

- Eddie

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Eddie

Expertise

I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.

Experience

I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.