title: I am trying to initialize an SDL_Window in a function but it always fails unless I define SDL_Window*win; as a global variable
body: <p>I am trying to initialize an SDL_Window in a function but it always fails unless I define SDL_Window*win; as a global variable.  Here is the code:</p>
  
  <pre><code>#include&lt;SDL2/SDL.h&gt;
  #include&lt;stdio.h&gt;
  
  #define SCREEN_WIDTH 800
  #define SCREEN_HEIGHT 600
  SDL_Surface*Init(SDL_Window*win,char*title,int x,int y,int w,int h,Uint32 flags);
  
  int main(int argc,char**argv){
  SDL_Surface *screen=NULL;
  SDL_Window*win=NULL;
  
  screen=Init(win,"SDL_Test",
              SDL_WINDOWPOS_CENTERED,
              SDL_WINDOWPOS_CENTERED,
              SCREEN_WIDTH,
              SCREEN_HEIGHT,
              SDL_WINDOW_SHOWN);
  
  SDL_FillRect(screen,NULL,SDL_MapRGB(screen-&gt;format,0xFF,0x00,0x00));
  SDL_UpdateWindowSurface(win);
  SDL_Delay(2000);
  
  
  }
  
  SDL_Surface*Init(SDL_Window*win,
                   char*title,
                   int x,
                   int y,
                   int w,
                   int h,
                   Uint32 flags){
  SDL_Surface*temp=NULL;
  
  if(SDL_Init(SDL_INIT_EVERYTHING)){
          printf("\nError : %s",SDL_GetError());
          SDL_ClearError();
          return NULL;
  }
  win=SDL_CreateWindow(title,x,6,w,h,flags);
  
  if(!win){
          printf("\nError: %s",SDL_GetError());
          SDL_ClearError();
          return NULL;
  }
  temp=SDL_GetWindowSurface(win);
  if(!temp){
          printf("\nError: %s",SDL_GetError());
          SDL_ClearError();
          return NULL;
  }
  return temp;
  }
  </code></pre>
  
  <p>If I declare SDL_Window*win as a global variable it shows a red screen(as it should) but if
  I define SDL_Window*win in main() and pass it to Init() it show a white screen(error?).</p>