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++ 中的内联
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- C++ 协变模板 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 近似搜索的工作原理 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01