On Jul 08 2023, Paul Smith wrote:

> Unfortunately because I am using limits.h from the clang intrinsics /
> resource directory (else many other things break), _POSIX_SEM_VALUE_MAX
> is not defined.

POSIX requires conforming implementations to define
_POSIX_SEM_VALUE_MAX.

> I can't quite figure out why, and my attempts to generate preprocessor
> output to track it down through the #include / #define maze have
> failed.  But the error I get (from clangd) suggests I want to be using
> _SC_SEM_VALUE_MAX and indeed if I make that change it works.

_SC_SEM_VALUE_MAX is related, but has a different role.  It is the
argument to sysconf to retrieve the runtime value of SEM_VALUE_MAX.

> Or at least expanding the above to use it as a last resort, as in:
>
>   #if defined(SEM_VALUE_MAX)
>       static constexpr ptrdiff_t _S_max = SEM_VALUE_MAX;
>   #elif defined(_POSIX_SEM_VALUE_MAX)
>       static constexpr ptrdiff_t _S_max = _POSIX_SEM_VALUE_MAX;
>   #else
>       static constexpr ptrdiff_t _S_max = _SC_SEM_VALUE_MAX;

That needs to be sysconf (_SC_SEM_VALUE_MAX), and thus is not suitable
for a constexpr.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

Reply via email to