472,958 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 1733
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.