C++ rmask 不命名类型
C++ rmask does not name a type
我有来自 sdl2 文档的以下代码:
//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 告诉我条件为真,但在编译时,它告诉我 rmask 没有命名类型。错误标记在 else 语句的第一行开始。首先,我该如何避免这种情况?其次,我什至需要 if 语句吗?
完整的错误日志是:
||=== 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)) ===|
已经通过将 fprintf 更改为 printf 修复了第五个错误
假设这段代码正是问题发生的地方(即,它没有从函数的中间提取出来),问题是在全局范围内不允许赋值语句。更改它以初始化变量(它们应该标记为 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
我有来自 sdl2 文档的以下代码:
//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 告诉我条件为真,但在编译时,它告诉我 rmask 没有命名类型。错误标记在 else 语句的第一行开始。首先,我该如何避免这种情况?其次,我什至需要 if 语句吗?
完整的错误日志是:
||=== 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)) ===|
已经通过将 fprintf 更改为 printf 修复了第五个错误
假设这段代码正是问题发生的地方(即,它没有从函数的中间提取出来),问题是在全局范围内不允许赋值语句。更改它以初始化变量(它们应该标记为 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