Post Reply 
 
Thread Rating:
  • 56 Votes - 4.27 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C/C++ macro expander?
Author Message
spacy51 Offline
VBA-M Developer
*******

Posts: 451
Joined: Mar 2008
Reputation: 3
Post: #1
C/C++ macro expander?
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.
(This post was last modified: 09-02-2009 07:05 PM by spacy51.)
08-31-2009 10:20 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Exophase Offline
VBA-M Contributor
*****

Posts: 33
Joined: Jun 2009
Reputation: 0
Post: #2
RE: C/C++ macro expander?
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.
09-02-2009 02:41 AM
Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 451
Joined: Mar 2008
Reputation: 3
Post: #3
RE: C/C++ macro expander?
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/prepro...ocessed.7z
(This post was last modified: 09-02-2009 07:37 PM by spacy51.)
09-02-2009 07:20 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Exophase Offline
VBA-M Contributor
*****

Posts: 33
Joined: Jun 2009
Reputation: 0
Post: #4
RE: C/C++ macro expander?
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.
09-03-2009 06:16 AM
Find all posts by this user Quote this message in a reply
Nach Offline
VBA-M Developer
*******

Posts: 41
Joined: Mar 2008
Reputation: 1
Post: #5
RE: C/C++ macro expander?
If you really looking to format code, grab a copy of Source Styler, it can be configured to whatever indentation style you prefer.
09-07-2009 10:30 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

 Quick Theme: