什么是标准调用实际上是宏 [英] What Standard Calls are Actually Macros
问题描述
我在此处询问了有关
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 ++标准库中定义为宏,即使C授予将其实现为功能的许可. [注意:在C中定义为宏的名称包括:
assert
,offsetof
,setjmp
,va_arg
,va_end
和va_start
. —尾注]
Names which are defined as macros in C shall be defined as macros in the C++ standard library, even if C grants license for implementation as functions. [ Note: The names defined as macros in C include the following:
assert
,offsetof
,setjmp
,va_arg
,va_end
, andva_start
. —end note ]
在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
标头
<cstdalign>
和标头<stdalign.h>
不应定义名为alignas
的宏.
The header
<cstdalign>
and the header<stdalign.h>
shall not define a macro namedalignas
.
标头<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 ++中作为关键字或运算符的标识符不应在C ++标准库标头中定义为宏.
Identifiers that are keywords or operators in C++ shall not be defined as macros in C++ standard library headers.
还有一个例外,即每[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
分类/比较功能的行为与C宏相同,其相应名称在C标准中的7.12.3(分类宏)和7.12.14(比较宏)中定义.三种浮点类型的每个函数都将重载,如下所示:
The classification/comparison functions behave the same as the C macros with the corresponding names defined in 7.12.3, Classification macros, and 7.12.14, Comparison macros in the C Standard. Each function is overloaded for the three floating-point types, as follows:
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);
这篇关于什么是标准调用实际上是宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!