小编ToB*_*een的帖子

什么可以在C99中返回bool类型?

什么是bool保证返回?我可以依赖bool类型来解释为0或1吗?如果bool的数值解释在C99中不可靠,那么有一个标准吗?在依赖bool进行算术运算时,我在LLVM,GCC或Visual C++中应该注意什么?

举个例子,如果我这样做:

// An example of calculating a possible stride in bytes.
// hasData(), is8bit(), and is16bit() return as bool type

unsigned int stride = object->hasData() * object->size() * 
                      (object->is8bit()  * sizeof(uint8_t) + 
                       object->is16bit() * sizeof(uint16_t));
Run Code Online (Sandbox Code Playgroud)

在示例中,我打赌bool类型只返回0或1.

c standards arithmetic-expressions integer-arithmetic

2
推荐指数
1
解决办法
205
查看次数