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

win32: replace the check for _MSC_VER by a more generic __has_include check #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jcelerier
Copy link
Contributor

The check has the same effect since support for stdbool.h and __has_include were
both introduced in the same MSVC version, but at least now it also works with MinGW

… check

The check has the same effect since support for stdbool.h and __has_include were
both introduced in the same MSVC version, but at least now it also works with MinGW
@gpakosz
Copy link
Owner

gpakosz commented Dec 10, 2024

According to this page https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance:

  • boolean type in <stdbool.h> support landed in VS 2015
  • __has_include support landed VS 2017 15.3

However this page https://devblogs.microsoft.com/cppblog/c99-library-support-in-visual-studio-2013/ says the stdbool.h header landed in VS 2013.

This page gives the corresponding values for _MSC_VER: https://learn.microsoft.com/en-us/cpp/overview/compiler-versions.

All in all, it seems that we want

#if (_MSC_VER >= 1800)
#include <stdbool.h>
#elif #defined (__has_include)
#if __has_include (<stdbool.h>)
#include <stdbool.h>
#endif
#else
#define bool int
#define false 0
#define true 1
#endif

@gpakosz
Copy link
Owner

gpakosz commented Dec 10, 2024

Or more conservatively

#if (_MSC_VER >= 1900)
#include <stdbool.h>
#elif #defined (__has_include)
#if __has_include (<stdbool.h>)
#include <stdbool.h>
#endif
#else
#define bool int
#define false 0
#define true 1
#endif

If we can't confirm that VS 2013 provides a working stdbool.h header.

@gpakosz
Copy link
Owner

gpakosz commented Dec 31, 2024

Hello @jcelerier 👋

Still around?

@jcelerier
Copy link
Contributor Author

wops, completely forgot about this sorry !

@jcelerier
Copy link
Contributor Author

jcelerier commented Dec 31, 2024

#if (_MSC_VER >= 1900)
  #include <stdbool.h>
#elif #defined (__has_include)
  #if __has_include (<stdbool.h>)
    #include <stdbool.h>
  #endif
  //here a hypothetical case of a windows compiler with __has_include and without stdbool.h would fail. Though maybe none exist? I'm not enough on windows to know but I feel that current MinGW wouldn't have any issue with that
#else
  #define bool int
  #define false 0
  #define true 1
#endif

I think there's a missing branch here. I don't think it's too problematic though in practice

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.

2 participants