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 @@
6868#define zig_x86
6969#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
7177#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
7278#define __STDC_WANT_IEC_60559_TYPES_EXT__
7379#endif
80
7481#include <float.h>
7582#include <limits.h>
7683#include <stdarg.h>
......@@ -82,7 +89,7 @@
8289
8390#if __STDC_VERSION__ >= 202311L
8491/* bool, true, and false are provided by the language. */
85#elif __STDC_VERSION__ >= 199901L
92#elif __STDC_VERSION__ >= 199901L || zig_has_include(<stdbool.h>)
8693#include <stdbool.h>
8794#else
8895typedef char bool;
......@@ -428,7 +435,7 @@ zig_extern void *memset (void *, int, size_t);
428435
429436/* ===================== 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>)
432439#include <stdint.h>
433440#else
434441
......@@ -3655,7 +3662,7 @@ zig_float_builtins(64)
36553662 res = zig_atomicrmw_expected; \
36563663} 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__)
36593666#include <stdatomic.h>
36603667typedef enum memory_order zig_memory_order;
36613668#define zig_memory_order_relaxed memory_order_relaxed