Date: Tue, 24 Nov 2026 03:00:25 +0300
On 24 Nov 2026 02:16, Alejandro Colomar wrote:
> Hi Andrey,
>
>> Date: 2026-11-24 01:18:01+0300
>> From: Andrey Semashev via Std-Proposals <std-proposals_at_[hidden]>
>>
>> On 24 Nov 2026 01:02, Alejandro Colomar wrote:
>>> Hi Andrey,
>>>
>>>> Date: 2026-11-24 00:50:14+0300
>>>> From: Andrey Semashev via Std-Proposals <std-proposals_at_[hidden]>
>>>>
>>>>> I think, the C's approach to introduce keywords as macros first does
>>>>> more harm than good.
>>>
>>> It has some nice side effects: you can test for the existence of the
>>> header (or of the macro) to know whether the feature is available:
>>>
>>> #if __has_include(<stdcountof.h>)
>>> # include <stdcountof.h>
>>> #else
>>> # define countof(a) (sizeof(a) / sizeof((a)[0]))
>>> #endif
>>>
>>> If you only have the keyword, then you need to complicate your build
>>> system.
>>
>> Why do you need a header as a proxy for core language feature detection?
>> There is __STDC_VERSION__,
>
> Compilers often provide features in older dialects, so the language
> version in which features are available is a bit uncertain.
That would be a non-standard extension and should be tested as such.
Specifically, check compiler-specific macros, likely with the compiler
version as well.
> It's more
> robust to query for the feature itself.
>
>> and there can be predefined feature detection
>> macros, like we have in C++. (Yes, C++ messed up library feature macros
>> initially, before <version> was introduced, but at least we got these
>> right in the end.) There are also __has_feature and similar extensions
>> that could be standardized, if needed.
>
> '#ifdef countof' or '#ifdef __has_include(<stdcountof.h>)' seem more
> robust than a query of the feature through some other means.
As Halalaluyafail3 has noted, testing for include is not robust at all.
'#ifdef countof' doesn't work if countof is a keyword. I don't have a
strong opinion of countof, but bool/true/false definitely should be
keywords.
> How do you
> know what to pass to __has_feature()?
Whatever the standard would tell me to. Same as with feature testing macros.
> Hi Andrey,
>
>> Date: 2026-11-24 01:18:01+0300
>> From: Andrey Semashev via Std-Proposals <std-proposals_at_[hidden]>
>>
>> On 24 Nov 2026 01:02, Alejandro Colomar wrote:
>>> Hi Andrey,
>>>
>>>> Date: 2026-11-24 00:50:14+0300
>>>> From: Andrey Semashev via Std-Proposals <std-proposals_at_[hidden]>
>>>>
>>>>> I think, the C's approach to introduce keywords as macros first does
>>>>> more harm than good.
>>>
>>> It has some nice side effects: you can test for the existence of the
>>> header (or of the macro) to know whether the feature is available:
>>>
>>> #if __has_include(<stdcountof.h>)
>>> # include <stdcountof.h>
>>> #else
>>> # define countof(a) (sizeof(a) / sizeof((a)[0]))
>>> #endif
>>>
>>> If you only have the keyword, then you need to complicate your build
>>> system.
>>
>> Why do you need a header as a proxy for core language feature detection?
>> There is __STDC_VERSION__,
>
> Compilers often provide features in older dialects, so the language
> version in which features are available is a bit uncertain.
That would be a non-standard extension and should be tested as such.
Specifically, check compiler-specific macros, likely with the compiler
version as well.
> It's more
> robust to query for the feature itself.
>
>> and there can be predefined feature detection
>> macros, like we have in C++. (Yes, C++ messed up library feature macros
>> initially, before <version> was introduced, but at least we got these
>> right in the end.) There are also __has_feature and similar extensions
>> that could be standardized, if needed.
>
> '#ifdef countof' or '#ifdef __has_include(<stdcountof.h>)' seem more
> robust than a query of the feature through some other means.
As Halalaluyafail3 has noted, testing for include is not robust at all.
'#ifdef countof' doesn't work if countof is a keyword. I don't have a
strong opinion of countof, but bool/true/false definitely should be
keywords.
> How do you
> know what to pass to __has_feature()?
Whatever the standard would tell me to. Same as with feature testing macros.
Received on 2026-11-24 00:00:32
