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 1572
On Sun, 25 Apr 2004 13:38:52 +0000 (UTC), J Krugman
<jk******@yahbi too.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 spare the time, I
would appreciate any comments (including words like evil and disgusting,
if you think they are applicable :-}) on the example here.
Kenny -
|
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 registers, r is register offset.
Does that read: return 32bits of data stored in memory location
SMC_BASE_ADDRESS+r.
|
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 way
assert.h can be implemented without using it? Are these decisions
related in anyway?
| |
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 further reading
suggests that since .foo is not a valid preproc. token that I can't
really do what I want, portably. The macro looks like this:
#define DMA_CHECK_SR_BIT(reg, REG, ch) do \
{ ...
|
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.
There are records in this Excel file with matches in the DAT
file.Whereever the records are marked "deleted" in the excel file,I
have to find the similar records on the DAT file and delete those
records.The records marked "add" in the excel file...
|
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 the value is between 0% and 100%. I also need the macro to give the user a message if a mistake occurs (using MsgBox).... I've done the first part, using IsNumeric, but I can not figure out how to do the other instructions.. Please help me out, Close...
|
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 but it didn't work to reset the printer settings.
Click on File then Print
Click on Properties to get to the Printing Preferences and under
Printing Shortcuts select
Letterhead Setting then
OK and OK again.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |