(4 * P)) -6ren">
gpt4 book ai didi

c - 禁食期警告 :"Arithmetic Overflow: 32-bit value is shifted, then cast to 64-bit value."

转载 作者:行者123 更新时间:2023-11-30 16:20:57 26 4
gpt4 key购买 nike

我已经声明了这样的宏:

#define F_MASK_4_BIT 0xF
#define GET_F_4BIT_MASK(F, P) (((F) & (F_MASK_4_BIT << (P * 4))) >> (4 * P))

使用这样的宏:

uint8_t Feature = GET_F_4BIT_MASK(E, P);

其中 Euint64_t 数据类型 Puint8_t 数据类型

Prefast 发出警告:C6297:算术溢出:32 位值被移位,然后转换为 64 位值。结果可能不是预期值。

如何解决这个问题?

最佳答案

这是非常不言自明的。如果P具有大于 7 的任何值(7*4=28,最大为31),F_MASK_4_BIT << (P * 4)会溢出。因为F_MASK_4_BITint 类型的整数常量.

通过使用适当的整数常量类型来修复此问题:

#define F_MASK_4_BIT 0xFull

关于c - 禁食期警告 :"Arithmetic Overflow: 32-bit value is shifted, then cast to 64-bit value.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55061707/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com