Path: chuka.playstation.co.uk!news From: "JohnT" Newsgroups: scee.yaroze.freetalk.english Subject: Re: ANSI C code Date: Wed, 11 Mar 1998 15:08:19 -0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 76 Message-ID: <6e693k$6nq4@chuka.playstation.co.uk> References: <6e5qdr$p7b1@emeka.playstation.co.uk> NNTP-Posting-Host: 194.75.167.131 X-Newsreader: Microsoft Outlook Express 4.72.2106.4 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Lewis_Evans@Playstation.sony.com wrote in message <6e5qdr$p7b1@emeka.playstation.co.uk>... > by mail2.fw-sj.sony.com (8.8.8/8.8.8) with ESMTP id CAA13561 > for ; Wed, 11 Mar 1998 02:57:26 -0800 (PST) >From: Lewis_Evans@Playstation.sony.com >To: news@playstation.co.uk > > >Owing to how I learnt C (without a textbook) I've been happily >producing yaroze code that doesn't seem to work on CodeWarrior, I >assume because my code isn't ANSI standard. What precautions do I have >to take to ensure codewarrior will compile my code? I've found out >about two... > >Both Net Yaroze compilers (GNU and CodeWarrior) are very close to >being fully ANSI C compliant. However, this really doesn't >sound like the cause of the trouble. > >when using #define, the defined part must be in brackets, and >at the end of IF and FOR loops, it seems to not want a semicolon after >the final closing brace. > >Not sure what you mean about brackets; for simple constants, >#define FALSE 0 >#define TRUE 1 >but for macros, yes, eg >#define abs(x) x >= 0 ? x : -x >will give problems with eg abs(y-5) and other expressions >since the expressions are just shoved into the macro and precedence >becomes tangled. > >With and , the syntax is thus > >if (expression) > { > // consequent action code here > } >the binds with the very next code block (eg single statement) >it finds, so >if (expression) ; >means 'if expression true, do the semicolon', ie do nothing no matter what. > binds in the same way, so >for (/*conditions*/) ; >means (for .....) do nothing, since the semicolon has no effects. > Lewis Hmmm, I think Robert meant he was doing this... if(expression) { // code here }; or for(expression) { // Code here }; Both are technically wrong as all closing braces ( } ) should not have a semicolon after them. Some compilers let this slip whilst others are strict about it. I suggest, Robert, that you get out of the habit of putting the semicolon after a closing brace. JohnT ------------------------------------------ Send e-mail to johnt@nettech.demon.co.uk Visit my web site at www.coco.net.uk/johnt ------------------------------------------