宏优于 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.
相关文章