Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > #defines

Reply
Thread Tools

#defines

 
 
Naren
Guest
Posts: n/a
 
      08-27-2003
Hello,

int main(){
int i=2,j=3;

printf("%d %d",i,j);

#define i j
#define j i

printf("%d %d",i,j);

}

What is the ouput in both the cases

Could anyone explain which tokens are considered while preprocessing.

Is the succesive preprocessor token replaced

thaanx in advance

Rgds,
Naren.





 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      08-27-2003
Naren wrote:

> Hello,
>
> int main(){
> int i=2,j=3;
>
> printf("%d %d",i,j);
>
> #define i j
> #define j i
>
> printf("%d %d",i,j);
>
> }
>
> What is the ouput in both the cases


[modulo some whitespace]

int main()
{
int i = 2, j = 3;
printf("%d %d", i, j);
printf("%d %d", i, j);
}





--
Martin Ambuhl

 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      08-27-2003
"Naren" <(E-Mail Removed)> writes:

> #define i j
> #define j i
>
> Could anyone explain which tokens are considered while preprocessing.


The preprocessor won't expand a macro name from within its own
expansion. So i expands to j, which expands to i, which ends the
chain of expansions. Similarly for j.

[snippage]
--
"Some programming practices beg for errors;
this one is like calling an 800 number
and having errors delivered to your door."
--Steve McConnell
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments