From 9a9f87c82e983e25b295b82234c55f3752a3f866 Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Wed, 22 Nov 2023 16:30:29 +0100 Subject: [PATCH] Help compilers to understand the error checking functions --- Sources/errors.c | 8 ++++---- Sources/errors.h | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Sources/errors.c b/Sources/errors.c index d699b71..ed94594 100644 --- a/Sources/errors.c +++ b/Sources/errors.c @@ -28,14 +28,14 @@ void error(debug_context context, const char *message, ...) { va_end(args); } -void check_args(bool check, debug_context context, const char *message, va_list args) { - if (!check) { +void check_args(bool test, debug_context context, const char *message, va_list args) { + if (!test) { error_args(context, message, args); } } -void check(bool check, debug_context context, const char *message, ...) { - if (!check) { +void check_function(bool test, debug_context context, const char *message, ...) { + if (!test) { va_list args; va_start(args, message); error_args(context, message, args); diff --git a/Sources/errors.h b/Sources/errors.h index 66f6b35..fa75834 100644 --- a/Sources/errors.h +++ b/Sources/errors.h @@ -1,16 +1,26 @@ #pragma once +#include #include #include #include +#if (__STDC_VERSION__ >= 201112L) +#define noreturn _Noreturn +#else +#define noreturn +#endif + typedef struct debug_context { const char *filename; uint32_t column; uint32_t line; } debug_context; -void error(debug_context context, const char *message, ...); -void error_args(debug_context context, const char *message, va_list args); -void check(bool check, debug_context context, const char *message, ...); -void check_args(bool check, debug_context context, const char *message, va_list args); +noreturn void error(debug_context context, const char *message, ...); +noreturn void error_args(debug_context context, const char *message, va_list args); +void check_function(bool test, debug_context context, const char *message, ...); +#define check(test, context, message, ...) \ + assert(test); \ + check_function(test, context, message, __VA_ARGS__) +void check_args(bool test, debug_context context, const char *message, va_list args);