小编ggl*_*uta的帖子

C++中的宏可以提高性能吗?

我是C++的初学者,我只是通过在需要时替换文本来阅读宏.在这种情况下,这是否意味着它使.exe运行得更快?这与内联函数有什么不同?

例如,如果我有以下宏:

#define SQUARE(x) ((x) * (x))
Run Code Online (Sandbox Code Playgroud)

正常功能:

int Square(const int& x)
{
    return x*x;
}
Run Code Online (Sandbox Code Playgroud)

和内联函数:

inline int Square(const int& x)
{
    return x*x;
}
Run Code Online (Sandbox Code Playgroud)

这三者之间的主要区别是什么,特别是内联函数和宏之间有什么区别?谢谢.

c c++ macros preprocessor inline

3
推荐指数
1
解决办法
2532
查看次数

标签 统计

c ×1

c++ ×1

inline ×1

macros ×1

preprocessor ×1