We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5252 - Build warning on MSVC: M_PI redefined
Summary: Build warning on MSVC: M_PI redefined
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: build (show other bugs)
Version: 2.0.12
Hardware: All Windows 10
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.16
Depends on:
Blocks:
 
Reported: 2020-08-09 18:26 UTC by Albert Vaca Cintora
Modified: 2020-12-09 14:53 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Albert Vaca Cintora 2020-08-09 18:26:27 UTC
On MSVC, including SDL.h and later including math.h, produces:

warning C4005: 'M_PI': macro redefinition

This is because SDL defines its own M_PI constant and math.h tries to define it again.

Instead of defining our own M_PI in SDL_stdinc.h, we should include math.h instead.

Note that, on top of that, MSVC needs _USE_MATH_DEFINES to be defined before including math.h, otherwise it won't define M_PI.
Comment 1 Albert Vaca Cintora 2020-08-10 23:22:19 UTC
I found this problem is quite more easy to reproduce than I thought. If _USE_MATH_DEFINES is set, just by including SDL.h we trigger the compiler warning in MSVC about M_PI being redefined.

This is due to the following include chain:

SDL.h -> SDL_main.h -> SDL_stdinc.h -> #define M_PI
SDL.h -> SDL_thread.h -> process.h -> corecrt_startup.h -> math.h -> #define M_PI again (if _USE_MATH_DEFINES is set)

I think SDL should not define M_PI itself and instead include math.h
Comment 2 Albert Vaca Cintora 2020-08-23 16:35:52 UTC
It seems this fork of SDL has a similar fix to what I'm proposing here, so at least one more person found this annoying: https://github.com/Jimbly/SDL/commit/2e42806dbca55a22b5b15a4a5becc779f2118735