lairworks / nas2d-core

NAS2D is an open source, object oriented 2D game development framework written in portable C++.
http://nas2d.lairworks.com
zlib License
10 stars 5 forks source link

Fix case of `#include <windows.h>` #1088

Closed DanRStevens closed 1 year ago

DanRStevens commented 1 year ago

This potentially matters for a Linux build using MingW, since the Linux filesystem is case sensitive. However, currently the MingW build does not trigger the Windows compile path here. Perhaps a sign the defines being checked here are a bit imprecise.

Reference: https://github.com/OutpostUniverse/OPHD/pull/1305#issuecomment-1509181851

DanRStevens commented 1 year ago

That matches what I recently read.

It seems the underscore is for the implementation reserved namespace, which means compilers can define it by themselves, whereas the non-prefixed version would need to be set in source code or project compiler config settings. That seems to be how MSVC handles the two. The _WIN32 value is defined by the compiler, whereas the WIN32 value is defined in <windows.h>. Obviously this makes it silly to use WIN32 as a check for including <windows.h>.

https://stackoverflow.com/questions/662084/whats-the-difference-between-the-win32-and-win32-defines-in-c

Also, as a side note, the last answer mentions that MingW defines WIN32 automatically, unless you use -std=c++??, like we do (-std=c++20). I was able to confirm that behaviour by dumping compiler defines.

https://stackoverflow.com/questions/2224334/gcc-dump-preprocessor-defines