On 2026-08-17 Kirill Makurin wrote:
> Documentation for `CreateThread` from Platform SDK for Windows Server
> 2003[1] says that the last parameter must be non-NULL on Windows
> 95/98/Me.
>
> I'm not sure if it is worth to add this attribute just for the sake
> of ancient Windows versions.
It's not about what is worth it, it's about correctness. When NULL might
be a valid argument, the nonnull attribute *must not* be added because
adding it could create bugs. The attribute has two effects:
(1) Compiler may optimize with the assumption that a NULL argument
results in undefined behavior. For example, gcc -O2 can optimize
bar() to always return 0. Try at <https://godbolt.org/z/axxva6dqf>.
#include <stddef.h>
void foo(char *buf) __attribute__((nonnull(1)));
int bar(char *buf)
{
int r = 0;
if (buf == NULL)
r = -1;
foo(buf);
return r;
}
(2) Enable diagnostics for -Wnonnull and -fsanitize=undefined.
With the nonnull attribute, one cannot get (2) without (1). Clang has
_Nonnull which does only (2), but GCC doesn't support it.
> In case of CRT functions
> `_beginthread[ex]`, I think we are better to provide a wrapper which
> could use a stack variable if this argument is NULL.
In my opinion, if a program needs to run on very old Windows, then it's
better to fix the program instead of adding this kind of wrapper to
mingw-w64.
--
Lasse Collin
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public