C 中以下宏的副作用是什么?嵌入式 C [英] What's the side effect of the following macro in C ? Embedded C

查看:10
本文介绍了C 中以下宏的副作用是什么?嵌入式 C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#define MIN(A,B) ((A) <=  (B) ? (A) : (B))

这是宏,有人问我如果我使用以下宏会有什么副作用:

this is the macro , I was asked what's the side effect if I used the following :

least = MIN(*p++, b);

注意:这是嵌入式 c 问题

推荐答案

它对 p++ 求值两次.此外,由于第一次评估改变了 p,第二次 它将指向不同的元素.所以返回值将是 *(initialp + 1)b.

It evaluates p++ twice. Also, since the first evaluation changes p, the second time around it will point to a different element. So the returned value will be *(initialp + 1) or b.

你应该自己试试.

这篇关于C 中以下宏的副作用是什么?嵌入式 C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆