Segmentation fault for C++ but not for C

hi all,

I write a simplest code like that:

#include <SDL/SDL.h>
int main ( int argc, char** argv )
{
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( “Unable to init SDL: %s\n”, SDL_GetError() );
return 1;
}
SDL_Quit();
return 0;
}

If I save it as c++ and build and run, a “Segmentation fault” appears, but if
I save it as c file, there is no this issue. I use sdl 1.2.14 with gcc4.1.1

Have you tried debugging it to see where segfault happens? might help. Also
try using -Wall on gcc, might give you some tips on whats going wrong.

Try adding #include <stdio.h> for printf, too.–

Leonardo

2010/8/26 tula

hi all,

I write a simplest code like that:

#include <SDL/SDL.h>
int main ( int argc, char** argv )
{
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( “Unable to init SDL: %s\n”, SDL_GetError() );
return 1;
}
SDL_Quit();
return 0;
}

If I save it as c++ and build and run, a “Segmentation fault” appears, but
if
I save it as c file, there is no this issue. I use sdl 1.2.14 with gcc4.1.1


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I write the app for a ARM9 board and have no tools to debug. my board use
hyperterminal as a console, though hyperterminal on PC, I can key in command
and will be executed by the board, of course, the command will be echoed on
hyperterminal when I key in command.

now I found another strange issue:

if I use “c” file, after “SDL_PollEvent” be called and exit the program,
there is no echo when I key in command,
for example, if I input “ls”, “ls” will not appear but the files in current
directory will be displayed.
if I use “c++” file, when the program exit, there is no change for command.
2010/8/26 Leonardo Guilherme <leonardo.guilherme at gmail.com>> Have you tried debugging it to see where segfault happens? might help. Also

try using -Wall on gcc, might give you some tips on whats going wrong.

Try adding #include <stdio.h> for printf, too.

Leonardo

2010/8/26 tula <@Je1>

hi all,

I write a simplest code like that:

#include <SDL/SDL.h>
int main ( int argc, char** argv )
{
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( “Unable to init SDL: %s\n”, SDL_GetError() );
return 1;
}
SDL_Quit();
return 0;
}

If I save it as c++ and build and run, a “Segmentation fault” appears, but
if
I save it as c file, there is no this issue. I use sdl 1.2.14 with
gcc4.1.1


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Well, then you’ll have to use the old printf debugging method, to find where
the program stops running. The way it is, I don’t have any clue. For that
echo problem, might be SDL_Quit not being called properly (or not being
called at all). AFAIK, the program you posted seems alright.–

Leonardo

2010/8/27 Je

I write the app for a ARM9 board and have no tools to debug. my board use
hyperterminal as a console, though hyperterminal on PC, I can key in command
and will be executed by the board, of course, the command will be echoed on
hyperterminal when I key in command.

now I found another strange issue:

if I use “c” file, after “SDL_PollEvent” be called and exit the program,
there is no echo when I key in command,
for example, if I input “ls”, “ls” will not appear but the files in
current directory will be displayed.
if I use “c++” file, when the program exit, there is no change for command.
2010/8/26 Leonardo Guilherme <@Leonardo_Guilherme>

Have you tried debugging it to see where segfault happens? might help. Also

try using -Wall on gcc, might give you some tips on whats going wrong.

Try adding #include <stdio.h> for printf, too.

Leonardo

2010/8/26 tula

hi all,

I write a simplest code like that:

#include <SDL/SDL.h>
int main ( int argc, char** argv )
{
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( “Unable to init SDL: %s\n”, SDL_GetError() );
return 1;
}
SDL_Quit();
return 0;
}

If I save it as c++ and build and run, a “Segmentation fault” appears,
but if
I save it as c file, there is no this issue. I use sdl 1.2.14 with
gcc4.1.1


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org