What Standard Calls are Actually Macros

后端 未结 1 446
一向
一向 2021-01-14 23:13

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

相关标签:
1条回答
  • 2021-01-14 23:37

    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);
    
    0 讨论(0)
提交回复
热议问题