If this is the case. Then there is another query .

While defining macros compiler support different styles of macros namely C9X 
and GNU style macros.

Suppose a code is compiled for GNU style and an object file of the same is 
created, will this later work on a C95 style supported compiler.

This anyways will be at runtime but since already the sense of the #define is 
made at compile time , will there be any issues of portability ?

When this code is run on a machine which say is upgraded to the higher version 
of the compiler which perhaps supports only one style of the macro version.

http://www.docs.hp.com/en/5969-4407/ch01s01.html



C9X

GNU

#define foo(f, ...) printf (f, __VA_ARGS__)

#define foo(f, s...) printf (f, s)



What would happen will the same code run ? It should if the object binaries are 
compatible across the upgraded compiler. I have perhaps answered the question ? 
But is that the case ?

Regards,
Kiran


From: [email protected] [mailto:[email protected]] On Behalf Of Brett 
McCoy
Sent: Wednesday, April 08, 2009 7:04 PM
To: [email protected]
Subject: Re: [c-prog] #define expansion runtime or compile time ?


On Wed, Apr 8, 2009 at 9:08 AM, Kiran Divakaran
<[email protected]<mailto:kiran_divakaran%40infosys.com>> wrote:

> I have a query with #defines in C.
>
> There is a -E compiler option which would expand the #define at compile time 
> and create an intermediate file and create the object file for the same.
>
> But normally do #defines get expanded at compile time or at run time.

Pre-processor directives technically are handled even before the
compile stage, they get expanded by the pre-processor before the code
is compiled. By the time the code is compiled, no traces of the
original pre-processor directives are left behind. Run gcc with the -E
option and you will see what the pre-processed code looks like -- you
will see the contents of, say, stdio.h included in the output and all
of the #defined macros expanded.

-- Brett
----------------------------------------------------------
"In the rhythm of music a secret is hidden;
If I were to divulge it, it would overturn the world."
-- Jelaleddin Rumi


**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
for the use of the addressee(s). If you are not the intended recipient, please 
notify the sender by e-mail and delete the original message. Further, you are 
not 
to copy, disclose, or distribute this e-mail or its contents to any other 
person and 
any such actions are unlawful. This e-mail may contain viruses. Infosys has 
taken 
every reasonable precaution to minimize this risk, but is not liable for any 
damage 
you may sustain as a result of any virus in this e-mail. You should carry out 
your 
own virus checks before opening the e-mail or attachment. Infosys reserves the 
right to monitor and review the content of all messages sent to or from this 
e-mail 
address. Messages sent to or from this e-mail address may be stored on the 
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***


[Non-text portions of this message have been removed]

Reply via email to