Mind that Clang also does *not* currently define `__STDC_NO_THREADS__`
for MinGW target. For MSVC target, this define was added in
<https://reviews.llvm.org/D112081>. Some of that discussion may also
apply here.
With glibc, apparently the compiler automatically includes
`stdc-predef.h` which allows the libc to set this define, however there
is no equivalent feature when it comes to MSVC and mingw-w64. It seems
the only way to set this define for mingw-w64 is to hardcode it into the
compiler.
On 9/11/2023 15:42, LIU Hao wrote:
在 2023/11/9 15:14, Antonin Décimo 写道:
I should be able to test this macro to choose to include `threads.h`
or not, even if it is not predefined, it cannot be located in
'threads.h'.
Someone may wish to use the same compiler consistently with older and
newer C runtime libraries. It is likely cumbersome if the compiler
would have had to look for a header before it could define a builtin
macro.
Is there no mechanism to allow this? gcc+glibc used to support it.
Clang currently has the correct behaviour on most systems.
Suppose: If clang currently defines `__STDC_NO_THREADS__`, does it
stop doing so if we upgrade mingw-w64 so we start to have <threads.h>?
I see some problems here, although it is allowed to define
__STDC_VERSION__ in C++ mode, most compilers don't define
this macro in C++.
`thread_local` is already a C++11 keyword.
Yes that's why the macro `thread_local` shouldn't be defined for C++.
In C23 the macro `thread_local` is removed, and `thread_local` becomes
a keyword too. The `_Thread_local` type specifier is removed.
It's a reserved word so a compiler is allowed to still provide it as
an extension [1]. And I wonder whether there is a good reason that it
will be removed. Keeping it as an extension has little cost, while
removing it would break valid C11 code.
Besides, providing an incomplete `threads.h` without all the C11
thread functions wouldn't be compliant, and quite counter-intuitive.
I'd say it's not good. However, defining `__STDC_NO_THREADS__` in the
compiler might not be even better; how can this compiler be used with
a newer runtime library that actually provides <threads.h>?
To fix my issue, I might define __STDC_NO_THREADS__ at
configure-time if the 'threads.h' header cannot be found.
Maybe you can use `__has_include(<threads.h>)` to check existence of
the header [2].
[1] https://gcc.godbolt.org/z/dxoTj3Eqr
[2]
https://gcc.gnu.org/onlinedocs/gcc-9.5.0/cpp/_005f_005fhas_005finclude.html
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public