• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Compiling Warning error when compile 0.4

binny

Member
Joined
Mar 16, 2017
Messages
65
Reaction score
12
This warnings errors show me when i try to compile my source code:
Code:
game.cpp: In constructor ‘Game::Game()’:
game.cpp:80:31: warning: iteration 2u invokes undefined behavior [-Waggressive-loop-optimizations]
   globalSaveMessage[i] = false;
                               ^
game.cpp:79:23: note: containing loop
  for(int32_t i = 0; i < 3; i++)
                       ^
In file included from game.cpp:18:0:
game.h: In member function ‘void Game::globalSave()’:
game.h:616:85: warning: iteration 2u invokes undefined behavior [-Waggressive-loop-optimizations]
 setGlobalSaveMessage(int16_t key, bool value) {globalSaveMessage[key] = value;}
                                                                              ^
game.cpp:6340:23: note: containing loop
  for(int16_t i = 0; i < 3; i++)
                       ^

my game.cpp:
hastebin

my game.h
hastebin


What is it?
How to fix?[/code]
 
1; You are using an integer (32bit) in the loop, but according to your header file it can max be a short value (16bit)
Cpp line 80 and h line 616, 617
And im no pro at cpp but at line 675 you specify that it should have a maximum of 2 values in it, but not what they data type they are.
And if you only got 2 diffrent values id just go with a simple bool, true or false.
1 = false, 2 = true.

And since you have a function for setting the value, why aren't you using it?
void setGlobalSaveMessage(int16_t key, bool value)
 
I'm sorry... I'm a nooba XD
I just downloaded the best sourcecode i found here on forum and came with this problem
GitHub - Fir3element/3777

I just was scared... Because I want a stable server XD

So what you said is that I should change:

game.cpp line 79
Code:
for(int32_t i = 0; i < 3; i++)
to
Code:
for(int16_t i = 0; i < 3; i++)

And the second part i do not understand
You mean that for(int32_t i = 0; i < 3; i++) or for(int16_t i = 0; i < 3; i++)
Should be for(int32_t i = 1; i < 3; i++) or for(int16_t i = 1; i < 3; i++)

Third i do not understand

Sorry to my newbie and thanks.
 
I'm sorry... I'm a nooba XD
I just downloaded the best sourcecode i found here on forum and came with this problem
GitHub - Fir3element/3777

I just was scared... Because I want a stable server XD

So what you said is that I should change:

game.cpp line 79
Code:
for(int32_t i = 0; i < 3; i++)
to
Code:
for(int16_t i = 0; i < 3; i++)

And the second part i do not understand
You mean that for(int32_t i = 0; i < 3; i++) or for(int16_t i = 0; i < 3; i++)
Should be for(int32_t i = 1; i < 3; i++) or for(int16_t i = 1; i < 3; i++)

Third i do not understand

Sorry to my newbie and thanks.

Change the int32_t to int16_t
 
Change the int32_t to int16_t

I made the change...
Code:
game.cpp: In constructor ‘Game::Game()’:
game.cpp:80:31: warning: iteration 2u invokes undefined behavior [-Waggressive-loop-optimizations]
   globalSaveMessage[i] = false;
                               ^
game.cpp:79:23: note: containing loop
  for(int16_t i = 0; i < 3; i++)
                       ^
In file included from game.cpp:18:0:
game.h: In member function ‘void Game::globalSave()’:
game.h:616:85: warning: iteration 2u invokes undefined behavior [-Waggressive-loop-optimizations]
   void setGlobalSaveMessage(int16_t key, bool value) {globalSaveMessage[key] = value;}
                                                                                     ^
game.cpp:6340:23: note: containing loop
  for(int16_t i = 0; i < 3; i++)
                       ^
 
I made the change...
Code:
game.cpp: In constructor ‘Game::Game()’:
game.cpp:80:31: warning: iteration 2u invokes undefined behavior [-Waggressive-loop-optimizations]
   globalSaveMessage[i] = false;
                               ^
game.cpp:79:23: note: containing loop
  for(int16_t i = 0; i < 3; i++)
                       ^
In file included from game.cpp:18:0:
game.h: In member function ‘void Game::globalSave()’:
game.h:616:85: warning: iteration 2u invokes undefined behavior [-Waggressive-loop-optimizations]
   void setGlobalSaveMessage(int16_t key, bool value) {globalSaveMessage[key] = value;}
                                                                                     ^
game.cpp:6340:23: note: containing loop
  for(int16_t i = 0; i < 3; i++)
                       ^

I have no ide on how to solve the warnings, but there is a way to get rid of them and thats to remove this flag; -Waggressive-loop-optimizations
Try compiling without it, because they are only warnings and you should still be able to compile with them.
 
Back
Top