468,306 Members | 1,132 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,306 developers. It's quick & easy.

any g++ compilation warning to detect empty if statement

Hi all,

recently encounter following bugs:

if (a b); //<- 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.

Aug 16 '07 #1
6 1571
lasing wrote:
recently encounter following bugs:

if (a b); //<- 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?
You need to ask in the compiler newsgroup about the settings for
any particular compiler. This is not a C++ language question.
if not, is it any source code checking tools can do it ?
I bet PC-lint can do it. [I just checked, it does: Info 721]
http://gimpel-online.com/MsgRef.html#721

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 16 '07 #2
On 2007-08-16 14:39, lasing wrote:
Hi all,

recently encounter following bugs:

if (a b); //<- 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 ?
Not really what you asked for, but if your editor can indent the files
you work on, use that function, 'return 0;' will then be on the same
level as the if-statement which should make you suspicious.

--
Erik Wikström
Aug 16 '07 #3
Hi!

lasing schrieb:
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 ?
My gcc manual tells me it is covered by "-Wextra". But in practice my
g++ 4.1.2 does not complain about it -.-

Frank
Aug 16 '07 #4

lasing <yu******@gmail.comwrote 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
Aug 16 '07 #5
BobR wrote:
lasing <yu******@gmail.comwrote 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.
How does that help?

if (somefunkycondition);
{
/* plenty of stuff in curly braces */
}

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 16 '07 #6

Victor Bazarov <v.********@comAcast.netwrote in message...
>
How does that help?

if (somefunkycondition);
{
/* plenty of stuff in curly braces */
}
So sorry I tried to suggest something. I'll refrain from such in the future!

[ Beam me up Scottie! There is no intelligent life on Earth. ]
--
Bob R
POVrookie
Aug 16 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

23 posts views Thread by Michel Bany | last post: by
2 posts views Thread by Aaron | last post: by
6 posts views Thread by alban | last post: by
27 posts views Thread by Terry | last post: by
6 posts views Thread by subramanian | last post: by
5 posts views Thread by Subrat | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.