dashed / tetris-sdl-c

🕹️ A toy project implementing a simple tetris clone in C for learning SDL 2.x.
MIT License
78 stars 20 forks source link

Fix "initializer element is not constant" error by adding #define #2

Closed Oxore closed 6 years ago

Oxore commented 6 years ago

There is such an error when using gcc on Arch Linux:

gcc -g `sdl2-config --cflags` -c src/init.c
In file included from src/init.h:1:0,
                 from src/init.c:1:
src/defs.h:25:34: error: initializer element is not constant
 static const int WINDOW_HEIGHT = PLAYFIELD_HEIGHT * ( BLOCK_SIZE + 1) + 1;
                                  ^~~~~~~~~~~~~~~~
src/defs.h:26:33: error: initializer element is not constant
 static const int WINDOW_WIDTH = PLAYFIELD_WIDTH * ( BLOCK_SIZE + 1) + 1;
                                 ^~~~~~~~~~~~~~~
In file included from src/init.h:3:0,
                 from src/init.c:1:
src/tetris.h:114:20: error: variably modified ‘playfield’ at file scope
 static Color_Block playfield[PLAYFIELD_HEIGHT * PLAYFIELD_WIDTH];
                    ^~~~~~~~~
make: *** [makefile:13: init.o] Error 1

Adding "#define" instead of "static const int" make compilation work fine.

dashed commented 6 years ago

@Oxore good catch! 👍