我从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已经修复了第五个错误
Uint32
进行了类型定义?否则你应该使用uint32_t
。 - davidhighUint32
。编辑:SDL在这里定义了Uint32
:http://hg.libsdl.org/SDL/file/8da3e4d25202/include/SDL_stdinc.h,而且`SDL_stdinc.h`被包含在`SDL.h`中。 - simonint
会发生什么?你需要包含stdint.h
/cstdint
来使用uint32_t
。 - simon