编辑:问题的解决方案是缺少原型。
当我调用uint8_t foo(uint16_t bar)
并将其返回值分配给 a 时,uint32_t temp
不仅 LSBtemp
被覆盖,而且更多。这怎么可能?编译器是 GCC。
调用代码:
uint32_t temp = 0xAAAAAAAA;
printf("[%x]\n", temp);
temp = foo(me->bar);
printf("[%x]\n", temp);
输出:
[aaaaaaaa]
[4081ff]
这里是 foo 执行的相关部分。
typedef struct CMOCK_foo_CALL_INSTANCE_tag
{
UNITY_LINE_TYPE LineNumber;
uint8_t ReturnVal;
int CallOrder;
uint16_t Expected_nGoNo;
} CMOCK_foo_CALL_INSTANCE;
uint8_t foo(uint16_t bar)
{
CMOCK_foo_CALL_INSTANCE* cmock_call_instance =
(CMOCK_foo_CALL_INSTANCE*)CMock_Guts_GetAddressFor(Mock.foo_CallInstance);
(...)
return cmock_call_instance->ReturnVal;
}