I asked a question here about assert
which is implemented in the standard as a macro, not a function.
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?
If we look at [headers] paragraphs 5 and 6 we have
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
, and va_start
. —end note ]
Names that are defined as functions in C shall be defined as functions in the C++ standard library.
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
The header <cstdalign>
and the header <stdalign.h>
shall not define a macro named alignas
.
The header <cstdbool>
and the header <stdbool.h>
shall not define macros named bool
, true
, or false
.
Although that those exceptions are covered by [headers]/7 as well
Identifiers that are keywords or operators in C++ shall not be defined as macros in C++ standard library headers.
There is also an exception that all classification macros defined in 7.12.3 Classification macros be overloaded by functions per [c.math]/10
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);