473,383 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 1746
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Richard | last post by:
How do I prevent a submit action from occurring if the select box has no value. The box is for a database search where the user must enter a keyword. Leaving the box empty triggers a blanket...
23
by: Michel Bany | last post by:
I am trying to parse responseXML from an HTTP request. var doc = request.responseXML; var elements = doc.getElementsByTagName("*"); the last statement returns an empty collection when running from...
27
by: MK | last post by:
I am a newbie. Please help. The following warning is issued by gcc-3.2.2 compiler (pc Linux): ================================================================== read_raw_data.c:51: warning:...
3
by: Dan | last post by:
Hi, I have a problem using an aspx page with a Control on it. I get the following error message Compiler Error Message: CS1595: 'Test.Class2' is defined in multiple places; using definition...
2
by: Aaron | last post by:
Hello all, I have 5 warnings only but I want to know how to "optimize" my code so that it is "clean." The warning is this with all 5 the same Warning 1 Variable 'strxxx' is used before it has...
6
by: alban | last post by:
Hello I have got some problems of compilation on a AIX IBM, I use the XLC compilator (And I can't install another one). I try to compile code Pro*c ".pc" (oracle), I need do a pre-compilation...
27
by: Terry | last post by:
I am getting the following warning for the below function. I understand what it means but how do I handle a null reference? Then how do I pass the resulting value? Regards Warning 1...
6
by: subramanian | last post by:
Consider the following program: #include <stdio.h> void myfn(const int **a) { static int i, j, k; a = &i; a = &j;
5
by: Subrat | last post by:
Hello, I am getting complation warning saying, warning : returning reference to temporary. The code from which it is coming: vector<boola_oObj; This vector is filled with all boolean values...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.