authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-12-02 09:42:39+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-12-03 12:07:34+01:00
log0e934c7df1aa82e72dfb3654e8f0f3a42bad9f01
treeabe832a341e4d1c790f9b9ac0ad384127ee9957e
parent1c43c2c209c3bfa501aedccdb803aa4f6a7ecafd
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

zig.h: Use C99/C11 headers if available regardless of language standard.

If present, these headers are usable even when compiling for older C language versions. Most notably, this enables zig.h atomics to work with slimcc and TinyCC in C99 mode (and earlier).

1 files changed, 10 insertions(+), 3 deletions(-)

lib/zig.h+10-3
...@@ -68,9 +68,16 @@...@@ -68,9 +68,16 @@
68#define zig_x8668#define zig_x86
69#endif69#endif
7070
71#if defined(__has_include)
72#define zig_has_include(include) __has_include(include)
73#else
74#define zig_has_include(include) 0
75#endif
76
71#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__77#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
72#define __STDC_WANT_IEC_60559_TYPES_EXT__78#define __STDC_WANT_IEC_60559_TYPES_EXT__
73#endif79#endif
80
74#include <float.h>81#include <float.h>
75#include <limits.h>82#include <limits.h>
76#include <stdarg.h>83#include <stdarg.h>
...@@ -82,7 +89,7 @@...@@ -82,7 +89,7 @@
8289
83#if __STDC_VERSION__ >= 202311L90#if __STDC_VERSION__ >= 202311L
84/* bool, true, and false are provided by the language. */91/* bool, true, and false are provided by the language. */
85#elif __STDC_VERSION__ >= 199901L92#elif __STDC_VERSION__ >= 199901L || zig_has_include(<stdbool.h>)
86#include <stdbool.h>93#include <stdbool.h>
87#else94#else
88typedef char bool;95typedef char bool;
...@@ -428,7 +435,7 @@ zig_extern void *memset (void *, int, size_t);...@@ -428,7 +435,7 @@ zig_extern void *memset (void *, int, size_t);
428435
429/* ===================== 8/16/32/64-bit Integer Support ===================== */436/* ===================== 8/16/32/64-bit Integer Support ===================== */
430437
431#if __STDC_VERSION__ >= 199901L || defined(zig_msvc)438#if __STDC_VERSION__ >= 199901L || defined(zig_msvc) || zig_has_include(<stdint.h>)
432#include <stdint.h>439#include <stdint.h>
433#else440#else
434441
...@@ -3655,7 +3662,7 @@ zig_float_builtins(64)...@@ -3655,7 +3662,7 @@ zig_float_builtins(64)
3655 res = zig_atomicrmw_expected; \3662 res = zig_atomicrmw_expected; \
3656} while (0)3663} while (0)
36573664
3658#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)3665#if (__STDC_VERSION__ >= 201112L || (zig_has_include(<stdatomic.h>) && !defined(zig_msvc))) && !defined(__STDC_NO_ATOMICS__)
3659#include <stdatomic.h>3666#include <stdatomic.h>
3660typedef enum memory_order zig_memory_order;3667typedef enum memory_order zig_memory_order;
3661#define zig_memory_order_relaxed memory_order_relaxed3668#define zig_memory_order_relaxed memory_order_relaxed