Skip to content

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

Open
jcelerier wants to merge 2 commits into
gpakosz:masterfrom
jcelerier:master
Open

win32: replace the check for _MSC_VER by a more generic __has_include check#44
jcelerier wants to merge 2 commits into
gpakosz:masterfrom
jcelerier:master

Conversation

@jcelerier

Copy link
Copy Markdown
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

gpakosz commented Dec 10, 2024

Copy link
Copy Markdown
Owner

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

gpakosz commented Dec 10, 2024

Copy link
Copy Markdown
Owner

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

gpakosz commented Dec 31, 2024

Copy link
Copy Markdown
Owner

Hello @jcelerier 👋

Still around?

@jcelerier

Copy link
Copy Markdown
Contributor Author

wops, completely forgot about this sorry !

@jcelerier

jcelerier commented Dec 31, 2024

Copy link
Copy Markdown
Contributor Author
#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