Skip to content

Commit

Permalink
Help compilers to understand the error checking functions
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Nov 22, 2023
1 parent 97327ef commit 9a9f87c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Sources/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 14 additions & 4 deletions Sources/errors.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
#pragma once

#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

#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);

0 comments on commit 9a9f87c

Please sign in to comment.