Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [c++] "warning: statement has no effect"

Credits go to Matthew Leverton and ReyBrujo for helping out!
This thread is locked; no one can reply to it. rss feed Print
[c++] "warning: statement has no effect"
Mark Oates
Member #1,146
March 2001
avatar

I'm getting this message using a for loop that actually does have an affect. How can I turn off this warning?

Oh, and while I'm at it how do I turn off "multiple definition" errors?

Matthew Leverton
Supreme Loser
January 1999
avatar

Write for (a;b;c); as for (a;b;c) {}.

Mark Oates
Member #1,146
March 2001
avatar

It already is. :-/ The for loop is from tinyXML's recommended method for reading from the document:

TiXmlElement* gimp_element;

for(gimp_element; gimp_element; gimp_element=gimp_element->NextSiblingElement())
{
  ...
}

ReyBrujo
Moderator
January 2001
avatar

Quote:

Oh, and while I'm at it how do I turn off "multiple definition" errors?

Correcting the code. That usually means you have defined a variable in a header that is being included in several. Declare the variable as extern in the header, and define it once in a source file without the modifier.

And try initializing the iterator variable.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Matthew Leverton
Supreme Loser
January 1999
avatar

Change it to:

for(gimp_element; gimp_element; (gimp_element=gimp_element->NextSiblingElement()))
{
}

Mark Oates
Member #1,146
March 2001
avatar

Matthew Leverton
Supreme Loser
January 1999
avatar

And by the way, if your for loop has no affect, it might suffer from schizophrenia. :-/

ReyBrujo
Moderator
January 2001
avatar

{"name":"effect_an_effect.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/c\/cc83c72c4c0078e428278e3a82ebf2c4.png","w":340,"h":423,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/c\/cc83c72c4c0078e428278e3a82ebf2c4"}effect_an_effect.png
XKCD

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Mark Oates
Member #1,146
March 2001
avatar

Quote:

it might suffer from schizophrenia.

it does. ;)

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

for(gimp_element; gimp_element; gimp_element=gimp_element->NextSiblingElement())

The first part of the for statement (where it sets the initial pre-loop setting) has no effect. That for loop would be rewritten as:

TiXmlElement* gimp_element;

gimp_element;
while(gimp_element) {
    ...
    gimp_element=gimp_element->NextSiblingElement();
}

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Johan Halmén
Member #1,550
September 2001

http://www.allegro.cc/files/attachment/593802

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

The first part of the for statement

Unless there's a clever macro going on; after all, this is C++. ;)

Tobias Dammers
Member #2,604
August 2002
avatar

I don't think you even need a macro to really fsck things up badly.

1struct GimpElement {
2 mutable int counter;
3 
4 GimpElement(int aCounter): counter(aCounter) {}
5 GimpElement(): counter(0) {}
6 operator bool() const { return (++counter < 42); }
7 GimpElement NextSiblingElement() const { return GimpElement(counter + 1); }
8 GimpElement& operator=(const GimpElement& rhs) { counter = rhs.counter + 1; }
9};
10 
11int main() {
12 GimpElement gimp_element;
13 for (gimp_element; gimp_element; gimp_element = gimp_element->NextSiblingElement())
14 ;
15 return 0;
16}

Untested though.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

CGamesPlay
Member #2,559
July 2002
avatar

Looks like you increment twice :)

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Go to: