Problem creating SDL_Rect in FOR loop

The code is included below. The first error is for

SDL_Rect rect(i);
parameter names (without types) in function declaration

I think the type is SDL_Rect and it isn’t a function declaration.

The lines below that are getting the error:
lvalue required as left operand of assignment rect(i).x = i*34;

This seems like a normal a valid C assignment to me. What am I missing?

TIA. Bill S.

Code:

#include <stdio.h>
#include <SDL2/SDL.h>

/* Window title */
#define WINDOW_TITLE “SDL2 Test”

int main( int argc, char* args[] ){

int i;
SDL_Init(SDL_INIT_VIDEO);

SDL_DisplayMode vmode;
SDL_GetDisplayMode(0, 0, &vmode);
SDL_Window *win1 = NULL;
win1 = SDL_CreateWindow("", 0, 0, vmode.w, vmode.h, SDL_WINDOW_SHOWN);

SDL_Renderer* ren1 = NULL;
ren1 = SDL_CreateRenderer( win1, 0, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor( ren1, 0, 0, 0, 255 ); //set render to black for background
SDL_RenderClear( ren1 ); // Clear window

SDL_SetRenderDrawColor( ren1, 0, 255, 0, 255 ); // green rectangles
for (i=0; i<5; i++)
{
SDL_Rect rect(i);

rect(i).x = i*34;
rect(i).y = 0;
rect(i).w = 32;
rect(i).h = 32;

SDL_RenderDrawRect(ren1, &rect(i));

SDL_RenderFillRect(ren1, &rect(i));
}
SDL_RenderPresent(ren1);
SDL_Delay(5000);

SDL_DestroyWindow(win1);
SDL_DestroyRenderer(ren1);
SDL_Quit();
return 0;
}

From what I see here, the problem would be that “rect(i)” is not a valid
identifier for a variable in C. Parentheses after an identifier either
mark a function declaration or a function call. Try something like
"rect_i" instead?

Jonny DOn Fri, Apr 10, 2015 at 11:13 PM, bilsch01 wrote:

The code is included below. The first error is for

SDL_Rect rect(i);
parameter names (without types) in function declaration

I think the type is SDL_Rect and it isn’t a function declaration.

The lines below that are getting the error:
lvalue required as left operand of assignment rect(i).x = i*34;

This seems like a normal a valid C assignment to me. What am I missing?

TIA. Bill S.

Code:

#include
#include

/* Window title */
#define WINDOW_TITLE “SDL2 Test”

int main( int argc, char* args[] ){

int i;
SDL_Init(SDL_INIT_VIDEO);

SDL_DisplayMode vmode;
SDL_GetDisplayMode(0, 0, &vmode);
SDL_Window *win1 = NULL;
win1 = SDL_CreateWindow("", 0, 0, vmode.w, vmode.h, SDL_WINDOW_SHOWN);

SDL_Renderer* ren1 = NULL;
ren1 = SDL_CreateRenderer( win1, 0, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor( ren1, 0, 0, 0, 255 ); //set render to black for
background
SDL_RenderClear( ren1 ); // Clear window

SDL_SetRenderDrawColor( ren1, 0, 255, 0, 255 ); // green rectangles
for (i=0; i<5; i++)
{
SDL_Rect rect(i);

rect(i).x = i*34;
rect(i).y = 0;
rect(i).w = 32;
rect(i).h = 32;

SDL_RenderDrawRect(ren1, &rect(i));

SDL_RenderFillRect(ren1, &rect(i));
}
SDL_RenderPresent(ren1);
SDL_Delay(5000);

SDL_DestroyWindow(win1);
SDL_DestroyRenderer(ren1);
SDL_Quit();
return 0;
}


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

SDL_Rect is a structure. If you are trying to define an array of five
rectangles, declare it before the loop:

SDL_Rect rect[5];

for (i=0; i<5; i++)
{
rect[i].x = i*34;
rect[i].y = 0;
rect[i].w = 32;
rect[i].h = 32;

}On Fri, Apr 10, 2015 at 8:13 PM, bilsch01 wrote:

The code is included below. The first error is for

SDL_Rect rect(i);
parameter names (without types) in function declaration

I think the type is SDL_Rect and it isn’t a function declaration.

The lines below that are getting the error:
lvalue required as left operand of assignment rect(i).x = i*34;

This seems like a normal a valid C assignment to me. What am I missing?

TIA. Bill S.

Code:

#include
#include

/* Window title */
#define WINDOW_TITLE “SDL2 Test”

int main( int argc, char* args[] ){

int i;
SDL_Init(SDL_INIT_VIDEO);

SDL_DisplayMode vmode;
SDL_GetDisplayMode(0, 0, &vmode);
SDL_Window *win1 = NULL;
win1 = SDL_CreateWindow("", 0, 0, vmode.w, vmode.h, SDL_WINDOW_SHOWN);

SDL_Renderer* ren1 = NULL;
ren1 = SDL_CreateRenderer( win1, 0, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor( ren1, 0, 0, 0, 255 ); //set render to black for
background
SDL_RenderClear( ren1 ); // Clear window

SDL_SetRenderDrawColor( ren1, 0, 255, 0, 255 ); // green rectangles
for (i=0; i<5; i++)
{
SDL_Rect rect(i);

rect(i).x = i*34;
rect(i).y = 0;
rect(i).w = 32;
rect(i).h = 32;

SDL_RenderDrawRect(ren1, &rect(i));

SDL_RenderFillRect(ren1, &rect(i));
}
SDL_RenderPresent(ren1);
SDL_Delay(5000);

SDL_DestroyWindow(win1);
SDL_DestroyRenderer(ren1);
SDL_Quit();
return 0;
}


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

[quote=“Brian Puthuff”]SDL_Rect is a structure. If you are trying to define an array of five rectangles, declare it before the loop:

SDL_Rect rect[5];

for (i=0; i<5; i++){??rect[i].x = i*34;??rect[i].y = 0;??rect[i].w = 32;??rect[i].h = 32;??..}

thanks. Bill S.