Jump to content
Visual Boy Advance-M
spacy51

C/C++ macro expander?

Recommended Posts

Is there a tool that takes a c/cpp file with macros as input and outputs the file with all macros expanded?

 

i could need something like this so I can easier read the arm core.

Share this post


Link to post
Share on other sites

Yes, you can usually use the compiler to do it. If you have gcc try this:

 

gcc file.c -E -o file_expanded.c

 

It won't matter if the file is actually C/C++, so long as its preprocessor directives are valid.

Share this post


Link to post
Share on other sites

If you want anyone to read expanded code I suggest you run it through some kind of formatting tool like indent. Macros suck because they're single line, so expansions contain a bunch of really long lines :/

 

It'd be great if mainstream C compilers had extensions to support multi-line macros.. no more line joins would be necessary, macro line numbers could be forwarded to compilation error code - good luck finding an error in a several thousand line macro - and they could be expanded in a way that doesn't look as awful.

Share this post


Link to post
Share on other sites

If you really looking to format code, grab a copy of Source Styler, it can be configured to whatever indentation style you prefer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×