Advantage of macro over in-line in C++(宏优于 C++ 中的内联)
问题描述
我们知道内联是有利的,因为它们由编译器检查,并且与宏相比,当作为参数传递时,相同的操作(如 ++x)不会多次计算.
We know that in-line are favorable as they are checked by the compiler and same operation ( like ++x ) does not evaluate more than once when passed as an argument as compared to macros.
但在一次采访中,有人问我在 C++ 中宏更适合内联的具体优势或情况.
But in an interview I was asked the specific advantages or the circumstances when a macro is more favorable to inline in C++.
有没有人知道这个问题的答案或者可以给出一个想法?
Does anyone know the answer or can give a thought on this question ?
推荐答案
我唯一能想到的就是有一些技巧可以用宏来完成,而内联函数却无法做到.在编译时将令牌粘贴在一起,以及那种骇客.
The only thing I can think of is there are some tricks that you can do with a macro that can't be done with an inline function. Pasting tokens together at compile-time, and that sort of hackery.
这篇关于宏优于 C++ 中的内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:宏优于 C++ 中的内联
基础教程推荐
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
