From fc2cbd992480a24257d21e67ed7f5ecf5f5042ae Mon Sep 17 00:00:00 2001 From: Quinn Date: Mon, 2 Jun 2025 12:15:49 +0200 Subject: [PATCH] switch from c17 to gnu99 I am choosing gnu99 over c99, since I am planning to use GNU extensions, like bswap. (in a future commit) Why I choose c99 over c17, is because this'll produce more portable code. c99 does not implement noreturn.h, thus I added it to the compiler attributes header. --- makefile | 2 +- src/error.h | 3 +-- src/util/atrb.h | 6 ++++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/makefile b/makefile index 334228e..de0064e 100644 --- a/makefile +++ b/makefile @@ -9,7 +9,7 @@ NAME := mcaselector-lite VERSION := 0.0.0 DEBUG ?= 0 CC ?= cc -CFLAGS += -c -std=c17 -Wall -Wextra -Wpedantic -Ilib -MMD -MP +CFLAGS += -c -std=gnu99 -Wall -Wextra -Wpedantic -Ilib -MMD -MP LDFLAGS += MARCH ?= $(shell uname -m) KERNEL ?= $(shell uname -s | tr '[:upper:]' '[:lower:]') diff --git a/src/error.h b/src/error.h index 9ca5140..a8ab993 100644 --- a/src/error.h +++ b/src/error.h @@ -4,7 +4,6 @@ #include #include #include -#include #include "util/atrb.h" @@ -14,7 +13,7 @@ atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void debug(char const*, atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void info(char const*, ...); atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void warn(char const*, ...); atrb_nonnull(1) atrb_format(printf, 1, 2) static inline void error(char const*, ...); -atrb_nonnull(1) atrb_format(printf, 1, 2) noreturn static inline void fatal(char const*, ...); +atrb_nonnull(1) atrb_format(printf, 1, 2) atrb_noreturn static inline void fatal(char const*, ...); atrb_nonnull(2) static inline void error_callback(int err, char const* const msg); // macro to write fmt vardiac args to buf diff --git a/src/util/atrb.h b/src/util/atrb.h index 23fbb37..3124ff2 100644 --- a/src/util/atrb.h +++ b/src/util/atrb.h @@ -8,6 +8,7 @@ #define atrb_unused #define atrb_pure #define atrb_const +#define atrb_noreturn #define atrb_format() #define atrb_nonnull() @@ -34,6 +35,11 @@ #define atrb_const __attribute__((const)) #endif +#if __has_attribute(noreturn) +#undef atrb_noreturn +#define atrb_noreturn __attribute__((noreturn)) +#endif + #if __has_attribute(format) #undef atrb_format #define atrb_format(...) __attribute__((format(__VA_ARGS__)))