使用宏或函数更好吗? [英] Is it better to use a macro or a function?

查看:77
本文介绍了使用宏或函数更好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用宏或函数更好吗?

Is it better to use a macro or a function?

推荐答案

madhawi< ma ******* @ gmail.comwrites:
madhawi <ma*******@gmail.comwrites:

使用宏或函数是否更好?
Is it better to use a macro or a function?



某些任务只能通过宏来完成。否则,使用

a功能:一般来说,它们更安全。

-

Ben Pfaff
http://benpfaff.org


madhawi写道:
madhawi wrote:

使用宏或函数是否更好?
Is it better to use a macro or a function?



类似函数的宏可能会出现许多问题,

参见C FAQ Question 10.1


所以尽可能使用函数。


-

Tor< torust [at] online [dot] no> ;

There are a number of things that can go wrong with function-like macros,
see C FAQ Question 10.1

so use a function, whenever you can.

--
Tor <torust [at] online [dot] no>


madhawi写道:
madhawi wrote:

使用宏或函数是否更好?
Is it better to use a macro or a function?



如果函数相对较短,使用宏会更好,因为它可以避免堆栈帧分配的开销(保存堆栈指针) />
调用者,保存调用函数中指令的返回地址

堆栈帧等)。


但是如果函数很长,使用宏可以调试噩梦。


Tejas Kokje

If functions are relatively short, using a macro is better since it
avoids overhead of stack frame allocation ( saving stack pointer of
caller,saving return address of the instruction in caller function on
the stack frame etc).

However if the functions are long, using macros can be debugging nightmare.

Tejas Kokje


这篇关于使用宏或函数更好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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