That program looks like it would quit automatically after about two seconds, provided no errors occur which would cause it to behave otherwise. If you want it to respond to the close window button, or to the escape key, you'd need to add a little input loop.
While in practise an error (e.g. no STARFIELDS.BMP file is found) may either be compensated for by checks in the rest of the code, or may cause a segfault, that you are doing no error checking and recovery means that it is possible that your program invokes
undefined behaviour, which means that your process might do unexpected things (such as hang).
Here is your program but with error checking added to the initialisation functions:
#include "SDL.h"
#include <iostream>
//The images
SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;
int main( int argc, char* args[] )
{
//Start SDL
if(SDL_Init( SDL_INIT_EVERYTHING ) < 0) {
std::cerr << "Failed to initialise SDL: " << SDL_GetError() << std::endl;
return 1;
}
//Set up screen
screen = SDL_SetVideoMode(640, 320, 32, SDL_SWSURFACE );
if(!screen) {
std::cerr << "Failed to set video mode: " << SDL_GetError() << std::endl;
SDL_Quit();
return 1;
}
//Load image
hello = SDL_LoadBMP( "STARFIELDS.BMP" );
if(!hello) {
std::cerr << "Failed to load image: " << SDL_GetError() << std::endl;
SDL_Quit();
return 1;
}
//Apply image to screen
SDL_BlitSurface( hello, NULL, screen, NULL );
//Update Screen
SDL_Flip( screen );
//Pause
SDL_Delay( 2000 );
//Free the loaded image
SDL_FreeSurface( hello );
//Quit SDL
SDL_Quit();
return 0;
}
SDL_BlitSurface() and SDL_Flip() can also fail, so for full correctness you'd need to add similar logic at these points too.