[libcxx-commits] [libcxx] [libcxx] Undefine all supported C math functions (PR #94533)
Petr Hosek via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jun 6 01:56:32 PDT 2024
petrhosek wrote:
> > We trying to use libc++ with FreeRTOS which defines some of the `math.h` standard C library functions as macros which is allowed by the C standard but it breaks libc++ headers. libc++ should undefine the macro before providing the symbol of the same name (just like it already does for some of them).
>
> Are you sure that the C standard allows this? The ones we `#undef`ine (`fpclassify`, `signbit`, `isfinite` and friends) are specified as macros in the standard, while `acos`, `atan` etc. are specified as functions.
Yes, this is explicitly mentioned in the section _7.1.4 Use of library functions_ of the C standard:
> Any function declared in a header may be additionally implemented as a function-like macro defined in the header, so if a library function is declared explicitly when its header is included, one of the techniques shown below can be used to ensure the declaration is not affected by such a macro. Any macro definition of a function can be suppressed locally by enclosing the name of the function in parentheses, because the name is then not followed by the left parenthesis that indicates expansion of a macro function name. For the same syntactic reason, it is permitted to take the address of a library function even if it is also defined as a macro.190). The use of #undef to remove any macro definition will also ensure that an actual function is referred to.
https://github.com/llvm/llvm-project/pull/94533
More information about the libcxx-commits
mailing list