C/C++ macro expander?

Non VBA-M Related on-topic discussion goes here, anything posted related to the emulator in this board will either be deleted or the content moved at staff discretion.
Post Reply
spacy51
Senior Member
Posts: 371
Joined: Tue Mar 18, 2008 4:59 pm

C/C++ macro expander?

Post by spacy51 »

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.

Last edited by spacy51 on Wed Sep 02, 2009 5:05 am, edited 1 time in total.
Exophase
Junior Member
Posts: 16
Joined: Sun Jun 07, 2009 9:56 pm

C/C++ macro expander?

Post by Exophase »

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.

spacy51
Senior Member
Posts: 371
Joined: Tue Mar 18, 2008 4:59 pm

C/C++ macro expander?

Post by spacy51 »

Ah, thanks.

 

I just found out even Microsoft's compiler can do that:

 

cl /P /C

 

It will generate a text file

 

 

Here are the arm & thumb cores, preprocessed:

http://spacy51.sp.funpic.de/VBA-M/preprocessed/arm_thumb_preprocessed.7z

Last edited by spacy51 on Wed Sep 02, 2009 5:37 am, edited 1 time in total.
Exophase
Junior Member
Posts: 16
Joined: Sun Jun 07, 2009 9:56 pm

C/C++ macro expander?

Post by Exophase »

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 [img]<fileStore.core_Emoticons>/emoticons/unsure.png[/img]/emoticons/unsure@2x.png 2x" width="20" height="20" />

 

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.

Nach
Junior Member
Posts: 31
Joined: Tue Mar 18, 2008 10:02 am

C/C++ macro expander?

Post by Nach »

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

Post Reply