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. 3 1554
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>>
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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Chris Reedy |
last post by:
For everyone -
Apologies for the length of this message. If you don't want to look
at the long example, you can skip to the end of the message.
And for the Python gurus among you, if you can...
|
by: John |
last post by:
Please, consider this macro:
#define mymacro(arg1, arg2) arg1 and arg2
Then it is used:
mymacro(boys, girls)
How is its expansion?
|
by: bob |
last post by:
Need help with c macro.
Have this call in my c program.
stub.c
SYMBOL(ALPHA) << no, dont want to change this to any other form.
SYMBOL(BETA)
Need a macro to expand each of above to this.
|
by: roaher |
last post by:
hi
I have some trouble reading this macro:
#define SMC_inl(r) (*((volatile dword *)(SMC_BASE_ADDRESS+(r))))
also consider that SMC_BASE_ADDRESS is address base of I/O mapped
peripherial...
|
by: glongword |
last post by:
As the assert macro should evaluate to a void expression, it should
not have an 'if statement' in its definition. Does this necessitate
the existence of a ternary conditional operator? Is there a...
|
by: Mark Odell |
last post by:
I'm running two different compilers against some hairy macros and one,
gcc, doesn't like my token pasting result so much. It says, " "." and
"foo" does not give a valid preprocessing token ". Some...
|
by: Roy |
last post by:
Hi all,
Thanks for your replies.I have to develop an application which will
read a .DAT file.There are several hundred records in this file.Also I
get another excel file with adds and deletes....
|
by: brokkoli88 |
last post by:
Hi!
I am having sort of a problem with a school assingnment.
I need to create a macro that checks if the content in a cell is a number. If the value is a percentage, I need the macro to check if...
|
by: mattia |
last post by:
I've came up with this:
FILE *fd;
char buf;
char fmt;
/* open fd */
sprintf(fmt, "%%%ds", sizeof(buf)-1);
while (fscanf(fd, fmt, buf) != EOF)
use_word(strdup(buf));
|
by: sandyt57 |
last post by:
I do Tech Support but do not know Visual Basic programming. In order to resolve a work process issue for one of our depts I need a macro that can do the following. I tried to create a macro in Word...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |