parse error
hi
i could not understand why compiler has put semi colon before else due t owhich this parse error comes....
thanks
#define exch(x,y) { int tmp; tmp=x; x=y; y=tmp; }
However that wouldn't work in some cases. The following code is meant to be an if-statement with two branches:
if(x>y)
exch(x,y); // Branch 1
else
do_something(); // Branch 2
But it would be interpreted as an if-statement with only one branch:
if(x>y) { // Single-branch
if-statement!!!
int tmp; // The one and only branch
consists
tmp = x; // of the block.
x = y;
y = tmp; }
; // empty statement
else // ERROR!!! "parse error
before else"
do_something();
________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
Quoted 9 lines · Ankit Jain
hi
i could not understand why compiler has put semi colon before else due t owhich this parse error comes....
thanks
#define
exch(x,y){ int tmp; tmp=x; x=y; y=tmp; }
#define exch(x,y) do { int tmp; tmp=x; x=y; y=tmp; } while(0);
Regards,
Signature · 2 lines
University of Athens I bet the human brain Physics Department is a kludge --Marvin Minsky
On Sat, 2004-09-25 09:29:01 +0300, Elias Athanasopoulos <[email protected]> wrote in message <[email protected]>:
Quoted 6 lines · Ankit Jain
Quoted 5 lines
hi
i could not understand why compiler has put semi colon before else due t owhich this parse error comes....
Quoted 6 lines
Quoted 4 lines
thanks
#define
exch(x,y){ int tmp; tmp=x; x=y; y=tmp; }#define
exch(x,y)do { int tmp; tmp=x; x=y; y=tmp; } while(0);
Nearly:-) Omit the last semicolon to make it work...
MfG, JBG
Signature · 4 lines
Jan-Benedict Glaw [email protected] . +49-172-7608481 _ O _ "Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg _ _ O fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! O O O ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
Quoted 8 lines · Jan-Benedict Glaw
On Sat, 2004-09-25 09:29:01 +0300, Elias Athanasopoulos <[email protected]> wrote in message <[email protected]>:
Quoted 6 lines · Ankit Jain
Quoted 5 lines
hi
i could not understand why compiler has put semi colon before else due t owhich this parse error comes....
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
thanks
#define
exch(x,y){ int tmp; tmp=x; x=y; y=tmp; }#define
exch(x,y)do { int tmp; tmp=x; x=y; y=tmp; } while(0);Nearly:-) Omit the last semicolon to make it work...
Right. :-) Actually after a lot of C Coding it's too difficult to develop the habit to omit a last semicolon in one line of code.
Regards,
Signature · 2 lines
University of Athens I bet the human brain Physics Department is a kludge --Marvin Minsky