EOSERV Forum > Game Development > Proper compiler flag?
Page: << 1 >>
Proper compiler flag?
Author Message
Post #199288 Proper compiler flag?

My current project has reached somewhere in the 10's of thousands of lines in code and it seems like my main issue is writing code to fast and for example I write:

if (a += b == c)  instead of if(a + b == c) .

I also had a similar issue when initializing a struct example:

struct MyStruct : public Shared

{

    int a,b,c;

    MyStruct(int a_,int b_,int c_) : a(a),b(b_),c(c_) {}

};

I didnt get a warning for a trying to initialize itself but it caused some -a's mostly! Its getting frustrating I'll push out a few hundred lines or a few functions and my only issue is something as small as that lol. I just wanted to know if there is a flag for this or?


8 years, 14 weeks ago
Post #199289 Re: Proper compiler flag?

Nothing I tried gave a warning for the first, but for the second clang and g++ both give two warnings when using -Wall and -Werror

lewis@home ~> cat test.cpp
struct Test{
int a;
Test(int b):
a(a){}
};
int main(){
Test test(10);
return(0);
}
lewis@home ~> g++ ./test.cpp -o test -Wall -Wextra
./test.cpp: In constructor 'Test::Test(int)':
./test.cpp:3:5: warning: 'Test::a' is initialized with itself [-Winit-self]
Test(int b):
^
./test.cpp: At global scope:
./test.cpp:3:14: warning: unused parameter 'b' [-Wunused-parameter]
Test(int b):
^
8 years, 14 weeks ago
Post #199290 Re: Proper compiler flag?

Thanks that picked up a couple warns I over looked! I was thinking maybe some kind of macro to check the conditional statments if theres no compiler flag or other option.

EDIT: I set a flag to -pedantic and it picked up

if(world->video->inv_y + iy  > world->video->inv_y > 301) break;

which is good cause its suppossed to be

  if(world->video->inv_y + iy  > world->video->inv_y+ 301) break;

but it still let this go with no warnings

 if(x_frame += y_frame = 0)
{

   Out("test LOL");
}

8 years, 14 weeks ago
Post #199303 Re: Proper compiler flag?

Just a bit of advice, but you really should use parenthesis around each expression. While you might get by with no errors, you may still encounter the 48 / 2(9+3) which will give you various answers depending on what type of machine or which math professor you ask. 

8 years, 14 weeks ago
Post #199308 Re: Proper compiler flag?

Another bad habit Ive developed usually if i run more than 2 comparisons in one statement ill enclose each. Thanks i will do that and looks like the answer i needed.

8 years, 13 weeks ago
Page: << 1 >>

EOSERV Forum > Game Development > Proper compiler flag?