From 6417c31a69ce06f35e00771fd2ecc87dbe48cd7a Mon Sep 17 00:00:00 2001 From: lemon Date: Tue, 24 Feb 2026 14:08:35 +0100 Subject: C23 true and false keywords --- c/c.c | 8 +++++--- doc/cstd.md | 1 - embedfilesdir.c | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/c/c.c b/c/c.c index d4e0aa6..019fb15 100644 --- a/c/c.c +++ b/c/c.c @@ -161,7 +161,7 @@ isexprtok(struct comp *cm) static const bool tks[] = { #define tk(x) [x] = 1 tk('+'), tk('-'), tk('*'), tk('&'), tk('~'), tk('!'), tk(TKINC), tk(TKDEC), - tk(TKWsizeof), tk(TKW_Alignof), tk(TKWalignof), + tk(TKWsizeof), tk(TKW_Alignof), tk(TKWalignof), tk(TKWtrue), tk(TKWfalse), tk('('), tk(TKNUMLIT), tk(TKCHRLIT), tk(TKSTRLIT), tk(TKW_Generic) #undef tk }; @@ -1080,6 +1080,9 @@ Unary: error(&tk.span, "bad %s literal %'tk", tk.t == TKNUMLIT ? "number" : "character", &tk); ex.ty.t = ty.t ? ty.t : TYINT; break; + case TKWtrue: case TKWfalse: + ex = mkexpr(ENUMLIT, tk.span, mktype(TYBOOL), .u = tk.t == TKWtrue); + break; case TKSTRLIT: ty = mktype(((const char []){TYCHAR, TYSHORT, TYINT})[tk.wide]); ex = mkexpr(ESTRLIT, tk.span, mkarrtype(ty, 0, tk.len+1), { .s.p = (void *)tk.s, .s.n = tk.len }); @@ -2312,8 +2315,7 @@ declspec(struct declstate *st, struct comp *cm, struct span *pspan) case TKWunsigned: arith |= KUNSIGNED; break; - case TKW_Bool: - case TKWbool: + case TKW_Bool: case TKWbool: if (arith & KBOOL) goto DupArith; arith |= KBOOL; break; diff --git a/doc/cstd.md b/doc/cstd.md index 63e39cd..9c235b4 100644 --- a/doc/cstd.md +++ b/doc/cstd.md @@ -25,7 +25,6 @@ A list of missing standard C features: - Digit separator ' - Attributes (`[[...]]` syntax) - Labels followed by declarations and } - - `true` and `false` keywords - `auto` for type inference, `typeof_unqual`, `constexpr` - `unreachable` macro in `` - checked int arithmetic (``) diff --git a/embedfilesdir.c b/embedfilesdir.c index 7d97f98..d1c8dd4 100644 --- a/embedfilesdir.c +++ b/embedfilesdir.c @@ -14,7 +14,9 @@ struct embedfile embedfilesdir[] = { typedef __typeof__((char*)0 - (char*)0) ptrdiff_t;\n\ typedef __typeof__(sizeof 0) size_t;\n\ typedef __typeof__(L'a') wchar_t;\n\ +#undef NULL\n\ #define NULL ((void *)0)\n\ +#undef offsetof\n\ #define offsetof(type, memb) ((size_t)((char *)&((type *)0)->memb - (char *)0))\n\ ")}, @@ -33,9 +35,11 @@ typedef __builtin_va_list __gnuc_va_list;\n\ {"stdbool.h", S("\ #pragma once\n\ +#if __STDC_VERSION__ < 202311L /* in C23 they are keywords */\n\ #define bool _Bool \n\ #define true 1\n\ #define false 0\n\ +#endif\n\ #define __bool_true_false_are_defined 1\n\ ")}, -- cgit v1.2.3