-1

I am using SDL2 for a game project and when i am trying to assign a value to a Uint32 variable, compiler throws this error :

int                     sdl_create_win(t_render *ress, t_map *map)                            
{
  SDL_CreateWindowAndRenderer(WIN_X, WIN_Y, 0, &ress->screen, &ress->rend);
  if (!ress->screen || !ress->rend)
    {
      fprintf(stderr,
              "Problem encountered while creating windows -> SDL Error : %s\n",
              SDL_GetError());
      SDL_Quit();
      return (-1);
    }
  ress->texture = SDL_CreateTexture(ress->rend,
                                    SDL_PIXELFORMAT_ARGB8888,
                                    SDL_TEXTUREACCESS_STATIC,
                                    map->x, map->y);
  ress->pixels = [map->x * map->y];
  memset(ress->pixels, 255, map->x * map->y * sizeof(Uint32));
  return (0);
}

compiler error is -->

30:18: error: expected expression before ‘[’ token 
ress->pixels = [map->x * map->y];

Thanks a lot for help !!

  • What is `Uint32`? Why not use the standard fixed width types? The error is not related to the type, but to your - adventurous - grammar. It is simply not C. – too honest for this site Jun 20 '16 at 13:36
  • 4
    What are the square brackets `[` and `]` around the expression `map->x * map->y` supposed to do? Maybe you need to [find a good beginners book](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list)? – Some programmer dude Jun 20 '16 at 13:37

1 Answers1

2

DS looks fine, Uint32 is a valid type in SDL.

If this syntax is supposed to be C, the error is ress->pixels = [map->x * map->y];.

Square brackets are not a part of the syntax when used that way.

Perhaps you should state what you want to accomplish by that line?

Ishay Peled
  • 2,783
  • 1
  • 23
  • 37