Path: chuka.playstation.co.uk!toby From: toby@angst.forefront.com.au (Toby Sargeant) Newsgroups: scee.yaroze.freetalk.english Subject: Re: ANSI C code Date: 12 Mar 1998 03:25:37 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 55 Message-ID: References: <6e5qdr$p7b1@emeka.playstation.co.uk> <6e693k$6nq4@chuka.playstation.co.uk> <3506CCE6.7301@127.0.0.1> NNTP-Posting-Host: ns.forefront.com.au X-Newsreader: slrn (0.9.4.6 UNIX) On Wed, 11 Mar 1998 17:41:58 +0000, Majik wrote: >> >> for(expression) >> { >> // Code here >> }; >> >> Both are technically wrong as all closing braces ( } ) should not have a >> semicolon after them. >;) >I don't think it is technically wrong, all that is being done is that a >null >statement is added after the braces, and this is syntactically okay. Without having my copy of K&R here, i can't say for sure, but my vote is for ';' being a legal expression. Some things to watch with #defines though: #define DEBUG(x) if(debug) printDebug(x) if (isBad) DEBUG(bad); else doGood(); Doesn't do what you'd expect. Because of the way else binds, the result is: if (isBad) if (debug) printDebug(bad); else doGood(); so you should always write macros like: #define DEBUG(x) do { if(debug) printDebug(x) } while(0) the do { } while(0) construct makes the compiler treat the entire block as a single statement, and protects you from the dreaded dangling else. it forces you to use the macro as a function, as well, which is good practice. > >I've had compilers _optimise_ out the variable 'tmp' before :$ so it >didn't do what it was supposed to. > There was a rumour that the ION Storm (was it ID back then?) team could only compile quake 2 on one of their development machines, because on every other (identically configured) machine, Visual C++ would generate code that just left the player spinning around in circles with no means of control. No compiler is perfect. GCC is (scarily enough) among the best. As long as you're not compiling convoluted C++, at least... toby.