In the listing below, an attempt to declare the rectangle "r" before the main() function is called results in an error.
error: 'r' does not name a type r.x = 150;<br>
Why must "r" be declared after main()?
#include <SDL2/SDL.h>
int main (int argc, char** argv) {
// Creat a rect at pos ( 50, 50 ) that's 50 pixels wide and 50 pixels high.
SDL_Rect r;
r.x = 150;
r.y = 150;
r.w = 200;
r.h = 100;
SDL_Window* window = NULL;
window = SDL_CreateWindow ("SDL2 rectangle", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
640,
480,
SDL_WINDOW_SHOWN
);
// Setup renderer
SDL_Renderer* renderer = NULL;
renderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor( renderer, 0, 0, 0, 255 ); // black background
SDL_RenderClear( renderer ); // Clear winow
SDL_SetRenderDrawColor( renderer, 0, 255, 255, 255 ); // rgba drawing color
// Render rect
SDL_RenderFillRect( renderer, &r );
// Render the rect to the screen
SDL_RenderPresent(renderer);
// Wait for 5 sec
SDL_Delay( 5000 );
SDL_DestroyWindow(window);
SDL_Quit();
return EXIT_SUCCESS;
}