I have the following code from the sdl2 documentation:
//Color declartions for later
Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
Codeblocks tells me that condition is true, but at compile time, it tells me that rmask doesn't name a type. The error is marked starting in the first line of else statement. Firstly, how do I avoid this? Secondly, do I even need the if statement?
The full error log was:
||=== Build: Debug in hayfysh (compiler: GNU GCC Compiler) ===|
/home/andrew/hayfysh/main.cpp|57|error: ‘rmask’ does not name a type|
/home/andrew/hayfysh/main.cpp|58|error: ‘gmask’ does not name a type|
/home/andrew/hayfysh/main.cpp|59|error: ‘bmask’ does not name a type|
/home/andrew/hayfysh/main.cpp|60|error: ‘amask’ does not name a type|
/home/andrew/hayfysh/main.cpp||In function ‘int newWindow(int, int, bool, const char*)’:|
/home/andrew/hayfysh/main.cpp|90|error: cannot convert ‘const char*’ to ‘FILE* {aka _IO_FILE*}’ for argument ‘1’ to ‘int fprintf(FILE*, const char*, ...)’|
||=== Build failed: 5 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
already fixed the fifth error by changing fprintf to printf
Assuming this code is exactly where the problem occurs (i.e., it hasn't been extracted from the middle of a function), the problem is that assignment statements aren't allowed at global scope. Change it to initialize the variables (should they be marked const?):
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
Uint32 rmask = 0xff000000;
Uint32 gmask = 0x00ff0000;
Uint32 bmask = 0x0000ff00;
Uint32 amask = 0x000000ff;
#else
Uint32 rmask = 0x000000ff;
Uint32 gmask = 0x0000ff00;
Uint32 bmask = 0x00ff0000;
Uint32 amask = 0xff000000;
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With