summarylogtreecommitdiffstats
path: root/c23-stdbool-compat.patch
blob: 80c7b1979b52b10e5b1d68728388e9fd1558e761 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
diff --git a/3rdparty/vgm/stdbool.h b/3rdparty/vgm/stdbool.h
index c4e89c161..dd683e906 100644
--- a/3rdparty/vgm/stdbool.h
+++ b/3rdparty/vgm/stdbool.h
@@ -1,15 +1,38 @@
-// custom stdbool.h to for 1-byte bool types
+// custom stdbool.h for 1-byte bool types (legacy)
+// Updated to be compatible with C23+ where `bool` is a keyword.
 #ifndef __CST_STDBOOL_H__
 #define __CST_STDBOOL_H__
 
-#ifndef __cplusplus	// C++ already has the bool-type
+/* C++ already has bool */
+#ifndef __cplusplus
 
-// the MS VC++ 6 compiler uses a one-byte-type (unsigned char, to be exact), so I'll reproduce this here
-typedef unsigned char	bool;
+  /*
+   * In C23 (and later), `bool` is a keyword, so we must not typedef it.
+   * Use the system <stdbool.h> in that case.
+   *
+   * 202311L is the C23 __STDC_VERSION__ value.
+   */
+  #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
 
-#define false	0x00
-#define true	0x01
+    #include <stdbool.h>
 
-#endif // ! __cplusplus
+  #else
+    /* Legacy: emulate MSVC 1-byte bool in pre-C23 C */
+    typedef unsigned char bool;
 
-#endif // ! __CST_STDBOOL_H__
+    #ifndef false
+      #define false 0x00
+    #endif
+
+    #ifndef true
+      #define true  0x01
+    #endif
+
+    #ifndef __bool_true_false_are_defined
+      #define __bool_true_false_are_defined 1
+    #endif
+  #endif /* __STDC_VERSION__ >= 202311L */
+
+#endif /* !__cplusplus */
+
+#endif /* !__CST_STDBOOL_H__ */