By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,053 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,053 IT Pros & Developers. It's quick & easy.

Need help reading macro-heavy code

P: n/a

I'm trying to read some source code that makes very heavy use of
macros and other pre-processor directives. To make matters worse,
macro definitions are stacked several layers deep (i.e. macros are
defined in terms of other macros, which are in turn defined in
terms of other macros, seemingly ad infinitum).

I tried reading the *.i files generated by the preprocessor (i.e.
by giving gcc the -E flag). To my surprise, the macros were not
fully expanded in the *.i files. For example, if

#define FOO(x) 2*(x)
#define BAR(x) FOO(x)

then occurrences of BAR(x) in the *.c files where expanded only to
FOO(x) in the corresponding *.i files, not to 2*(x).

What can I do to generate source code with all the macros fully
expanded? Are there tools that are useful when attempting to read
such code?

Thanks!

jill

--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.

Nov 14 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sun, 25 Apr 2004 13:38:52 +0000 (UTC), J Krugman
<jk******@yahbitoo.com> wrote:

I'm trying to read some source code that makes very heavy use of
macros and other pre-processor directives. To make matters worse,
macro definitions are stacked several layers deep (i.e. macros are
defined in terms of other macros, which are in turn defined in
terms of other macros, seemingly ad infinitum).

I tried reading the *.i files generated by the preprocessor (i.e.
by giving gcc the -E flag). To my surprise, the macros were not
fully expanded in the *.i files. For example, if

#define FOO(x) 2*(x)
#define BAR(x) FOO(x)

then occurrences of BAR(x) in the *.c files where expanded only to
FOO(x) in the corresponding *.i files, not to 2*(x).

What can I do to generate source code with all the macros fully
expanded? Are there tools that are useful when attempting to read
such code?

Ask in a newsgroup specific to your compiler. Most have some method
of obtaining the output from the pre-processor which is what you are
looking for.
<<Remove the del for email>>
Nov 14 '05 #2

P: n/a
J Krugman wrote:
I'm trying to read some source code that makes very heavy use of
macros and other pre-processor directives. To make matters worse,
macro definitions are stacked several layers deep (i.e. macros are
defined in terms of other macros, which are in turn defined in
terms of other macros, seemingly ad infinitum).

I tried reading the *.i files generated by the preprocessor (i.e.
by giving gcc the -E flag). To my surprise, the macros were not
fully expanded in the *.i files. For example, if

#define FOO(x) 2*(x)
#define BAR(x) FOO(x)

then occurrences of BAR(x) in the *.c files where expanded only to
FOO(x) in the corresponding *.i files, not to 2*(x).
Questions about gcc should be addressed to a gnu newsgroup. Before you
post there, however, make sure that you have a clear question. My copy
of gcc using -E translates

#define FOO(x) 2*(x)
#define BAR(x) FOO(x)

int main(void)
{
int x = 3, y;
y = FOO(x);
return 0;
}

to

int main(void)
{
int x = 3, y;
y = 2 * (x);
return 0;
}

This suggests to me that you are doing something other than that that
you claim.
What can I do to generate source code with all the macros fully
expanded?
Use gcc -E. See above.
Are there tools that are useful when attempting to read
such code?


I have no idea what that's supposed to mean. Use your eyes and brain to
read it.
Nov 14 '05 #3

P: n/a
Hello folk

you can just use cpp file

to make easy reading an obfuscated source (as you mentioned
before :) ) try first to indent the source code
then make a tag table for emacs try this
etags thesourcecode.c
and fetch the function or macro (it can be supported in some version) by
alt-x tags-search ....

this make reading an understanding a foreign source easily
Nov 14 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.