Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just #define _GNU_SOURCE and _USE_MATH_MACROS unconditionally #1419

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sethk
Copy link
Contributor

@sethk sethk commented Mar 19, 2025

Remove definitions of M_PI from source.

  • _USE_MATH_MACROS is required by MSVC when compiling against UCRT.
  • _GNU_SOURCE is required for other functions that are extensions to

The macros in math.h are not part of POSIX, but are visible by default so long as you don't declare you are trying to be strictly POSIX-conformant by defining _POSIX_C_SOURCE or _XOPEN_SOURCE.

Tested on:

  • macOS 11.7.9 (it's old, sorry)
    Apple clang version 13.0.0
    x86_64-apple-darwin20.6.0

  • FreeBSD 14.2-RELEASE
    FreeBSD clang version 18.1.6
    x86_64-unknown-freebsd14.2

  • Amazon Linux release 2 (Karoo) 4.14.336-253.554.amzn2.x86_64
    cc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-17)
    x86_64-redhat-linux

  • Windows 11 24H2:

    • MSYS2 c++ (GCC) 13.3.0
      x86_64-pc-msys
      msys-2.0.dll runtime

    • CLANG64 clang version 19.1.4
      x86_64-w64-windows-gnu
      ucrtbase.dll runtime

    • MINGW64 cc.exe (Rev2, Built by MSYS2 project)
      14.2.0 x86_64-w64-mingw32
      msvcrt.dll runtime

    • UCRT64 cc.exe (Rev2, Built by MSYS2 project)
      14.2.0 x86_64-w64-mingw32
      ucrtbase.dll runtime

    • Microsoft (R) C/C++ Optimizing Compiler Version 19.42.34433 for x64
      (Requires a few additional PRs that I will submit)

Remove definitions of M_PI from source.
- _USE_MATH_MACROS is required by MSVC when compiling against UCRT.
- _GNU_SOURCE is required for other functions that are extensions to

The macros in math.h are not part of POSIX, but are visible by default
so long as you don't declare you are trying to be strictly
POSIX-conformant by defining _POSIX_C_SOURCE or _XOPEN_SOURCE.

Tested on:

- macOS 11.7.9 (it's old, sorry)
  Apple clang version 13.0.0,
  x86_64-apple-darwin20.6.0

- FreeBSD 14.2-RELEASE
  FreeBSD clang version 18.1.6
  x86_64-unknown-freebsd14.2

- Amazon Linux release 2 (Karoo) 4.14.336-253.554.amzn2.x86_64
  cc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-17)
  x86_64-redhat-linux

- Windows 11 24H2:
  - MSYS2 c++ (GCC) 13.3.0
    x86_64-pc-msys
    msys-2.0.dll runtime

  - CLANG64 clang version 19.1.4
    x86_64-w64-windows-gnu
    ucrtbase.dll runtime

  - MINGW64 cc.exe (Rev2, Built by MSYS2 project) 14.2.0
    x86_64-w64-mingw32
    msvcrt.dll runtime

  - UCRT64 cc.exe (Rev2, Built by MSYS2 project) 14.2.0
    x86_64-w64-mingw32
    ucrtbase.dll runtime

  - Microsoft (R) C/C++ Optimizing Compiler Version 19.42.34433 for x64
    (Requires a few additional PRs that I will submit)
@sethk
Copy link
Contributor Author

sethk commented Apr 1, 2025

@alyssais and @kylophone , can you please review? I tried to simplify the defines here to also support MSVC on Windows, FreeBSD, and everything else imaginable without having to redefine M_PI in multiple places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant