Suspicious semicolon?

Get answers to all your basic programming questions. No Ogre questions, please!
N_K
Greenskin
Posts: 115
Joined: Wed Dec 07, 2011 9:05 pm
x 4

Suspicious semicolon?

Post by N_K »

Hello all.

I decided to base my "game" on the Advanced Ogre Framework (many thanks to Spacegaier and jacmoe for making it, it's an enormous help). It compiles fine, however, I got a few warnings, and I wanted to eliminate them. I managed to do it, apart from a few "Suspicious semicolon" warnings in DotSceneLoader.cpp. The code looks like this:

Code: Select all

if(pElement)
        ;
Indeed a semicolon, and indeed suspicious. I'm not that experienced with C++, so, to be honest, I'm not entirely sure what is this supposed to be. If it's an empty 'if' statement, isn't it supposed to be something like this:

Code: Select all

if(pElement)
{     

}
?

Could someone shed some light on this? Thank you in advance. And sorry for being a total noob...
PhilipLB
Google Summer of Code Student
Google Summer of Code Student
Posts: 550
Joined: Thu Jun 04, 2009 5:07 pm
Location: Berlin
x 108

Re: Suspicious semicolon?

Post by PhilipLB »

Hi,

the compiler warns you here not to run into traps like this:

Code: Select all

if (foo);
  bar();
bar(); gets always executed here because of the semicolon.
Google Summer of Code 2012 Student
Topic: "Volume Rendering with LOD aimed at terrain"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Mattan Furst


Volume GFX, accepting donations.
User avatar
Zonder
Ogre Magi
Posts: 1172
Joined: Mon Aug 04, 2008 7:51 pm
Location: Manchester - England
x 76

Re: Suspicious semicolon?

Post by Zonder »

This is one reason I always insist on using braces with if statements :)
There are 10 types of people in the world: Those who understand binary, and those who don't...
N_K
Greenskin
Posts: 115
Joined: Wed Dec 07, 2011 9:05 pm
x 4

Re: Suspicious semicolon?

Post by N_K »

So it's indeed an empty 'if' statement. Thank you all for your help.
Valentin Perrelle
Halfling
Posts: 54
Joined: Thu Sep 15, 2011 4:14 pm
x 2

Re: Suspicious semicolon?

Post by Valentin Perrelle »

The C++ Grammar allow a statement to be an empty expression. So this is how is considered a semi-colon alone. Since the if statement only applies to the following statement, it thus applies to the empty statement in your code.