Sujet : Re: C23 thoughts and opinions
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.cDate : 24. May 2024, 16:10:31
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v2qal7$2c8rq$3@dont-email.me>
References : 1 2 3
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 23/05/2024 18:40, Keith Thompson wrote:
Michael S <already5chosen@yahoo.com> writes:
[...]
Removed
[...]
7) static_assert is not provided as a macro defined in <assert.h>
(becomes a keyword)
8) thread_local is not provided as a macro defined in <threads.h>
(becomes a keyword)
>
[...]
7) bad. Breaks existing code for weak reason
8) bad. Breaks existing code for weak reason
In pre-C23, _Static_assert and _Thread_local are keywords, and
static_assert and thread_local are macros that expand to those keywords.
In C23, _Static_assert, _Thread_local, static_assert, and thread_local
are all keywords. Code that simply uses the old ugly keywords would not
break.
Code that does something like "#ifdef static_assert". I suppose the
headers could have retained the old macro definitions.
#define static_assert static_assert
#define thread_local thread_local
The sort of code that could theoretically break is when you have definitions like this:
#define STATIC_ASSERT_NAME_(line) STATIC_ASSERT_NAME2_(line)
#define STATIC_ASSERT_NAME2_(line) assertion_failed_at_line_##line
#define static_assert(claim, warning) \
typedef struct { \
char STATIC_ASSERT_NAME_(__COUNTER__) [(claim) ? 2 : -2]; \
} STATIC_ASSERT_NAME_(__COUNTER__)
That works in any C version, until C23, almost as well as _static_assert. I used this when C11 support was rare in the tools I used.
While using #define for a C keyword is undefined behaviour, in practice I think you'd have a hard time finding code and a compiler that used such a macro and which did not work just as well in C23 mode.
(I don't know if anyone is in the habit of declaring macros named "thread_local".)