From 71ca0b176f7a643ef7606d12f4001b445a115092 Mon Sep 17 00:00:00 2001 From: Daniele Cocca Date: Tue, 15 Mar 2022 18:45:02 +0000 Subject: [PATCH] CBE: `#undef linux` in zig.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compilers will sometimes `#define linux 1` if the operating system in use is Linux. This clashes with the code produced by the C backend when processing the stdlib, e.g. std.Target.Os.VersionRange [^1] which is a struct containing a field named `linux`. The output of the C backend doesn't rely on this macro being defined, and other code also shouldn't rely on it -- e.g. quoting from the GCC documentation [^2]: """ The C standard requires that all system-specific macros be part of the reserved namespace. All names which begin with two underscores, or an underscore and a capital letter, are reserved for the compiler and library to use as they wish. However, historically system-specific macros have had names with no special prefix; for instance, it is common to find unix defined on Unix systems. [...] We are slowly phasing out all predefined macros which are outside the reserved namespace. You should never use them in new programs, and we encourage you to correct older code to use the parallel macros whenever you find it. We don’t recommend you use the system-specific macros that are in the reserved namespace, either. It is better in the long run to check specifically for features you need """ [^1]: https://github.com/ziglang/zig/blob/8c32d989c995f8675f1824fb084245b833b26223/lib/std/target.zig#L224 [^2]: https://gcc.gnu.org/onlinedocs/cpp/System-specific-Predefined-Macros.html#System-specific-Predefined-Macros --- src/link/C/zig.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/link/C/zig.h b/src/link/C/zig.h index ce22b5221f..7259ba19ce 100644 --- a/src/link/C/zig.h +++ b/src/link/C/zig.h @@ -1,3 +1,5 @@ +#undef linux + #if __STDC_VERSION__ >= 201112L #define zig_noreturn _Noreturn #define zig_threadlocal thread_local