我试图通过以下示例中的temp变量检查“temp =(volatile unsigned short *)add”中的添加值:
main() {
unsigned short add = 0x01;
unsigned short val = 0x00;
unsigned short *temp;
temp = (volatile unsigned short*) add;
*temp = val;
//@ assert &temp == (unsigned short) 0x01;
}
但我在“// @ assert&temp ==(unsigned short)0x01”这一行得到了这个错误。“
[kernel] user error: incompatible types unsigned short and unsigned short **
[kernel] user error: stopping on file "test_func_call.c" that has errors. Add '-kernel-msg-key pp'for preprocessing command.
我知道这可能与C有关,但我也使用Frama-C的标签。希望我能收到关于通过Frama-C检查添加值的答案。
关于:
assert &temp == (unsigned short) 0x01;
这是试图将temp
(在堆栈上)的地址与某个地址(堆栈上的该位置除外)进行比较。自然地,assert()
被触发
访问内存中特定地址内容的正确方法是:
temp = *(unsigned short *) 0x01;