宏优于 C++ 中的内联

Advantage of macro over in-line in C++(宏优于 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++ 中的内联

基础教程推荐