您的位置:首页 > 产品设计 > UI/UE

Why do I get "Value computed is not used" when working with pointers?

2012-03-19 15:42 615 查看
摘自:http://tigcc.ticalc.org/doc/faq.html#99

Q:    I have a variable and a pointer to it, for example,

int a, ptr_to_a = &a;

When I tried to modify the variable "a" indirectly using the pointer, like in

*ptr_to_a++;

the compiler reports to me "Value computed is not used". What is wrong here?

A:    Note that although operators '++' and '*' have the same precedence, '++' will be evaluated first, so this expression will be evaluated as

*(ptr_to_a++);

i.e. it increases the pointer, then reads the value from it (which is not used for anything). This is not what do you want, of course. To perform what do you want (i.e. to increase the variable pointed to by the pointer), use parentheses to change the order
of evaluation, i.e. use

(*ptr_to_a)++;

This will work as expected.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  compiler
相关文章推荐