[SDL] seg fault despite Extern screen

Mike Shal marfey at gmail.com
Tue Feb 19 07:49:31 PST 2008

On 2/19/08, Peter Cutting <peter.cutting at gmail.com> wrote:
> I found the bug. The demo declared screen twice. Once statically and once in
> main(). So the one in main was initialised but the static one (used by the
> filebrowser code) was not.

So the toolchain you're using is based on gcc? If so, you can enable
warnings to let you know ahead of time about such things:

--- foo.c ---
#include <SDL.h>

SDL_Surface *screen;

int main(void)
        SDL_Surface *screen;
        return 0;
--- end ---

$ gcc -c foo.c `sdl-config --cflags`
(no output)


$ gcc -Wshadow -c foo.c `sdl-config --cflags`
foo.c: In function 'main':
foo.c:7: warning: declaration of 'screen' shadows a global declaration
foo.c:3: warning: shadowed declaration is here

Of course you wouldn't know ahead of time that -Wshadow would tell you
about your specific problem, but if that's the kind of thing that
periodically gives you trouble, you may want to leave that flag on.
The gcc man page has info about that flag, and many others you may
want to consider using during development.


More information about the SDL mailing list