freelanceprogrammers.org Forum Index » C

What`s the order of evaluation of preprocessor?


View user's profile Post To page top
nkhattar@... Posted: Wed Jan 05, 2005 5:36 pm


Joined: 05 Jan 2005

Posts: 2
What`s the order of evaluation of preprocessor?
#define f(a,b) a##b
#define g(a)   #a
#define h(a) g(a)
 
int main()
{
  printf("%s
",h(f(1,2)));
  printf("%s
",g(f(1,2)));
  return 0;
}
 
Output of this program will be :
12
f(1,2)
 
I am unable to understand the output.
Plz explain it.
 
Thanks in advance
 
Naveen
Reply with quote
Send private message
View user's profile Post To page top
sflam108 Posted: Thu Jan 06, 2005 1:52 am


Joined: 25 Jul 2003

Posts: 48
What`s the order of evaluation of preprocessor?
Reply embeddd...

> From: Naveen Khattar [mailto:nkhattar@...]
> Sent: Wednesday, January 05, 2005 5:37 AM
> To: programmers-town@yahoogroups.com
> Cc: Naveen Khattar
> Subject: (PT) What`s the order of evaluation of preprocessor?
>
> #define f(a,b) a##b
> #define g(a) #a
> #define h(a) g(a)
>
> int main()
> {
> printf("%s
",h(f(1,2)));
> printf("%s
",g(f(1,2)));
> return 0;
> }
>
> Output of this program will be :
> 12
> f(1,2)
>
> I am unable to understand the output.

Do you know how preprocessor directives work?


> Plz explain it.

Already answered in the archive:
< http://groups.yahoo.com/group/Programmers-Town/message/3060 >

HTH
Shyan
Reply with quote
Send private message
View user's profile Post To page top
nkhattar@... Posted: Thu Jan 06, 2005 12:27 pm


Joined: 05 Jan 2005

Posts: 2
What`s the order of evaluation of preprocessor?
-----Original Message-----
From: Shyan Lam [mailto:sflam@...]
Sent: Thursday, January 06, 2005 1:22 AM
To: Programmers-Town@yahoogroups.com
Subject: RE: (PT) What`s the order of evaluation of preprocessor?


Reply embeddd...

> From: Naveen Khattar [mailto:nkhattar@...]
> Sent: Wednesday, January 05, 2005 5:37 AM
> To: programmers-town@yahoogroups.com
> Cc: Naveen Khattar
> Subject: (PT) What`s the order of evaluation of preprocessor?
>
> #define f(a,b) a##b
> #define g(a) #a
> #define h(a) g(a)
>
> int main()
> {
> printf("%s
",h(f(1,2)));
> printf("%s
",g(f(1,2)));
> return 0;
> }
>
> Output of this program will be :
> 12
> f(1,2)
>
> I am unable to understand the output.

Do you know how preprocessor directives work?
That`s what I want to know.


> Plz explain it.

Already answered in the archive:
< http://groups.yahoo.com/group/Programmers-Town/message/3060 >

HTH
Shyan





To unsubscribe : programmers-town-unsubscribe@yahoogroups.com


Yahoo! Groups Links
Reply with quote
Send private message
View user's profile Post To page top
karthik_bala... Posted: Thu Jan 06, 2005 4:22 pm


Joined: 06 Jan 2005

Posts: 2
What`s the order of evaluation of preprocessor?
Hi,
#define f(a,b) a##b
#define g(a) #a
#define h(a)

Here ,# represent string tokenizers.It just concatenate the two strings.Thatis
where ever f(a,b) is used it will be replaced by ab.So,as per urprogram it will be replaces as 12.
I think u understand.
Thank U
Karthikeyan.R



Quoting nkhattar@...:

>








-----OriginalMessage-----
From: Shyan Lam [mailto:sflam@...]
Sent: Thursday, January 06, 2005 1:22 AM
To:Programmers-Town@yahoogroups.com
Subject: RE: (PT) What`s the orderof evaluation of preprocessor?


Replyembeddd...

> From: Naveen Khattar[mailto:nkhattar@...]
> Sent: Wednesday, January 05, 20055:37 AM
> To: programmers-town@yahoogroups.com
> Cc:Naveen Khattar
> Subject: (PT) What`s the order of evaluation ofpreprocessor?
>
> #define f(a,b) a##b
> #defineg(a)   #a
> #define h(a) g(a)
>
> intmain()
> {
>  printf("%sn",h(f(1,2)));
>  printf("%sn",g(f(1,2)));
>   return0;
> }
>
> Output of this program will be:
> 12
> f(1,2)
>
> I am unable tounderstand the output.

Do you know how preprocessordirectives work?
That`s what I want to know.


>Plz explain it.

Already answered in the archive:
href="http://groups.yahoo.com/group/Programmers-Town/message/3060">http://groups.yahoo.com/group/Programmers-Town/message/3060>

HTH
Shyan





Tounsubscribe : programmers-town-unsubscribe@yahoogroups.com


Yahoo! Groups Links















To unsubscribe :programmers-town-unsubscribe@yahoogroups.com










align=center>Yahoo! GroupsSponsor


align=center>ADVERTISEMENThref="http://us.ard.yahoo.com/SIG=129bj7pn1/M=298184.5639630.6699735.3001176/D=groups/S=1705006788:HM/EXP=1105079504/A=2495202/R=0/SIG=11evjk50a/*http://www.netflix.com/Default?mqso=60188913" alt="">src="http://us.a1.yimg.com/us.yimg.com/a/ne/netflix/121504_y1204_a_300250a.gif" alt="click here" width="300" height="250"border="0">

width=1 height=1src="http://us.adserver.yahoo.com/l?M=298184.5639630.6699735.3001176/D=groups/S=:HM/A=2495202/rand=893197294">










Yahoo! Groups Links

To visit your group on the web, go to:href="http://groups.yahoo.com/group/Programmers-Town/">http://groups.yahoo.com/group/Programmers-Town/ 
To unsubscribe from this group, send an email to:href="mailto:Programmers-Town-unsubscribe@yahoogroups.com?subject=Unsubscribe">Programmers-Town-unsubscribe@yahoogroups.com 
Your use of Yahoo! Groups is subject to the href="http://docs.yahoo.com/info/terms/">Yahoo! Terms ofService.
Reply with quote
Send private message
View user's profile Post To page top
sflam108 Posted: Thu Jan 06, 2005 9:59 pm


Joined: 25 Jul 2003

Posts: 48
What`s the order of evaluation of preprocessor?
Reply at end...

> -----Original Message-----
> From: Naveen Khattar [mailto:nkhattar@...]
> Sent: Thursday, January 06, 2005 12:28 AM
> To: Programmers-Town@yahoogroups.com
> Subject: RE: (PT) What`s the order of evaluation of preprocessor?
>
>
> > Do you know how preprocessor directives work?
> That`s what I want to know.

How about some reading first:

<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/htm
l/_predir_preprocessor_operators.asp>

(URL might line-break by mail client)

Consult your compiler`s documentation and see how to generate a
"preprocessed" output to see the result just after preprocessing.

HTH
Shyan
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help