我得到了一段适用__attribute__((const))
于某些功能的代码。现在,我宁愿在它可用时不删除它,但另一方面,我确实想要更便携,所以 - 我想说
#if some condition here
#define ATTRIBUTE(an_attribute) __attribute__((an_attribute))
#else
#define ATTRIBUTE(an_attribute)
#endif
void foo(int x) ATTRIBUTE(const)
条件应该是什么?
笔记:
- 我知道,对于 C++17,我们将其作为适当的 C++ 属性;但我不能假设使用了 C++17。事实上,让我们假设这不是为了让事情变得简单。
- 如果你也能回答问题,加分
__attribute__((pure))
。