[SDL] Need help tracking down a SegFault

Erik esigra at gmail.com
Sun Feb 24 11:04:16 PST 2008


Michael Sullivan skrev:
> On Sun, 2008-02-24 at 19:20 +0100, Erik wrote:
>   
>> Michael Sullivan skrev:
>>     
>>> michael at camille ourrpg $ make && ./main
>>> g++ -W -Wall `sdl-config --cflags`  -c battle.cpp
>>> battle.cpp: In member function 'bool Battle::initialize()':
>>> battle.cpp:85: warning: name lookup of 'i' changed
>>> battle.cpp:11: warning:   matches this 'i' under ISO standard rules
>>> battle.cpp:58: warning:   matches this 'i' under old rules
>>>       
>> Fix those warnings first and see if it helps.
>>     
>
> What does that even mean; "name lookup of 'i' changed?

It means that some old unofficial versions of C++ may interpret your 
code differently than it should be interpreted according to the 
standard. Just make sure that all variables go out of scope as soon as 
they are not used any more. Whenever possible, variables should be 
declared inside the statement where they are used:
   for (uint32_t i ...
instead of:
   uint32_t i;
   for (i = ...

and:
   if (T * const  p = ...
instead of:
   T * const p = ...
   if (p) ...

If you can not declare the variable inside a statement like that, create 
the smallest possible scope for it with {}:
   {
      uint32_t i;
      for (i = ...
         ...
      //  use i after the loop
   } //  make sure that i goes out of scope immediately when it is no 
longer used



More information about the SDL mailing list