问题描述
假设一个整数表达式包含多个无符号整数类型uint16_t
和uint32_t
。该表达式包含一个带括号的子表达式,其中所有元素的类型均为uint16_t
。
在评估子表达式之前,应将带括号的子表达式中的元素提升为uint32_t
吗?
例如:
#include <stdint.h>
#include <stdio.h>
int main(void)
{
uint16_t a16 = 0x2000;
uint16_t b16 = 0x3000;
uint32_t c32 = 0x00000001;
uint32_t d32;
// Should (a16 * b16) be evaluated to 0x06000000,or to 0x0000?
// Should d32 be evaluated to 0x06000001,or to 0x00000001?
d32 = c32 + (a16 * b16);
printf("d32=0x%08x\n",d32);
return 0;
}
在 ideone 在线编译器中进行尝试,建议在乘法之前将a16
和b16
提升为uint32_t
。这是C标准强制要求的吗?为什么不在括号内时求值为uint16_t
?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)