问题描述
我在此处询问了有关 assert
,它在标准中以宏而非函数的形式实现.
I asked a question here about assert
which is implemented in the standard as a macro, not a function.
这引起了我一个问题,因为assert
似乎是采用参数形式的函数:assert(true)
因此,我尝试将其用作:std::assert(true)
,当然是一个宏,它没用.
This had caused me an issue because the way that assert
appears to be a function in the way it takes a parameter: assert(true)
Thus I tried to use it as: std::assert(true)
and of course being a macro that didn't work.
我的问题是:标准库是否提供了其他任何带有参数的宏?
My question is this: Are there any other macros provided by the standard library which would appear as functions that take parameters?
推荐答案
如果我们看一下[header]第5和6段,我们就有
If we look at [headers] paragraphs 5 and 6 we have
在C中定义为函数的名称应在C ++标准库中定义为函数.
Names that are defined as functions in C shall be defined as functions in the C++ standard library.
因此,如果在C中将其定义为宏,则它将在C ++中为宏.虽然有一些例外.摘自[support.runtime]第7和8段
So, if it is defined as a macro in C, it will be a macro in C++. There are a couple of exceptions though. from [support.runtime] paragraphs 7 and 8
标头<cstdbool>
和标头<stdbool.h>
不应定义名为bool
,true
或false
的宏.
The header <cstdbool>
and the header <stdbool.h>
shall not define macros named bool
, true
, or false
.
尽管这些例外也包含在[headers]/7中
Although that those exceptions are covered by [headers]/7 as well
还有一个例外,即每[c.math]/10
There is also an exception that all classification macros defined in 7.12.3 Classification macros be overloaded by functions per [c.math]/10
int fpclassify(float x);
bool isfinite(float x);
bool isinf(float x);
bool isnan(float x);
bool isnormal(float x);
bool signbit(float x);
bool isgreater(float x, float y);
bool isgreaterequal(float x, float y);
bool isless(float x, float y);
bool islessequal(float x, float y);
bool islessgreater(float x, float y);
bool isunordered(float x, float y);
int fpclassify(double x);
bool isfinite(double x);
bool isinf(double x);
bool isnan(double x);
bool isnormal(double x);
bool signbit(double x);
bool isgreater(double x, double y);
bool isgreaterequal(double x, double y);
bool isless(double x, double y);
bool islessequal(double x, double y);
bool islessgreater(double x, double y);
bool isunordered(double x, double y);
int fpclassify(long double x);
bool isfinite(long double x);
bool isinf(long double x);
bool isnan(long double x);
bool isnormal(long double x);
bool signbit(long double x);
bool isgreater(long double x, long double y);
bool isgreaterequal(long double x, long double y);
bool isless(long double x, long double y);
bool islessequal(long double x, long double y);
bool islessgreater(long double x, long double y);
bool isunordered(long double x, long double y);
这篇关于什么是标准调用实际上是宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!