C中的宏和函数有什么区别? [英] What is the difference between a macro and a function in C?

查看:14
本文介绍了C中的宏和函数有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C 中的宏和函数有什么区别?请告诉我一个可以使用宏和函数的应用程序?

What is the difference between a macro and a function in C? Please tell me one application where I can use macros and functions?

推荐答案

基本的区别是编译函数和预处理宏.当您使用函数调用时,它将被转换为 ASM CALL,其中包含所有这些堆栈操作以传递参数和返回值.当您使用宏时,C 预处理器将使用宏翻译所有字符串,然后编译.

The basic difference is that function is compiled and macro is preprocessed. When you use a function call it will be translated into ASM CALL with all these stack operations to pass parameters and return values. When you use a MACRO, C preprocessor will translate all strings using macro and than compile.

使用宏的缺点是它们隐藏了实现.如果有 bug 就更难找到了.

Minus of using macros is that they hide implementation. Its way harder to find bug if have one.

这篇关于C中的宏和函数有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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