mingw-w64 i686-7.1.0编译SDL2 test程序

xiaoxiao2021-02-28  87

在使用mingw-w64 i686-7.1.0-posix-sjlj-rt_v5-rev0版编译SDL2 test程序的过程中,遇到如下错误

testatomic.c:106:1: note: in expansion of macro 'SDL_COMPILE_TIME_ASSERT'  SDL_COMPILE_TIME_ASSERT(size, CountTo>0); /* check for rollover */

换编译器mingw32单独编译该文件,却没有错误。

查看testatomic.c文件中的代码出错的位置

#define NThreads 2 #define CountInc 100 #define VALBITS (sizeof(atomicValue)*8) #define atomicValue int #define CountTo ((atomicValue)((unsigned int)(1<<(VALBITS-1))-1)) #define NInter (CountTo/CountInc/NThreads) #define Expect (CountTo-NInter*CountInc*NThreads) SDL_COMPILE_TIME_ASSERT(size, CountTo>0); /* check for rollover */

SDL_COMPILE_TIME_ASSERT应该是想测试把1左移31位后,是否发生溢出。输出CountTo的值为2147483647,按理应该能通过测试的。但不知是不是预处理器中有bug,实际该检测不能通过。对代码作如下修改,指明1为无符号类型,编译通过。

#define CountTo ((atomicValue)((unsigned int)(1u<<(VALBITS-1))-1))

转载请注明原文地址: https://www.6miu.com/read-78426.html

最新回复(0)