lasing <yung2004@gmail.com> wrote in message...
> Hi all,
>
> recently encounter following bugs:
>
> if (a > b); file://<- bug in the careless ";" here
> return 0;
>
> Due to the extra ";" in the if statement line, it always return 0.
>
> Anyone know g++ has any compiler - warning flag to detect this kind of
> error? if not, is it any source code checking tools can do it ?
> thanks, Eric.
>
Change your bad habits. If you get in the habit of always using
curly-braces, you will save yourself some of the 'gotchas'.
if( b ){}
if( a > b ){ return 0; }
if( a > b ){} else{ /* stuff */ }
for( /* .... */ ){}
for( /* .... */ ){ /* stuff */ }
while( a > b ){ /* stuff */; ++b; }
while( /* something */ ){ ; } // if that's what you intended.
etc.
--
Bob R
POVrookie