diff --git a/build.c b/build.c index f0fc461..5c1295b 100644 --- a/build.c +++ b/build.c @@ -3,7 +3,7 @@ /// // Build config stuff #define VERY_DEBUG 0 -#define RUN_TESTS 0 +#define RUN_TESTS 1 typedef struct Context_Extra { int monkee; diff --git a/main.c b/main.c index 5de451c..580dcc3 100644 --- a/main.c +++ b/main.c @@ -43,14 +43,14 @@ int oogabooga_main(int argc, char **argv) { (void)hello; #ifdef DEBUG - printf("Hello, balls! (debug)\n"); + print("Hello, balls! (debug)\n"); #endif #ifdef RELEASE - printf("Hello, balls! (release)\n"); + print("Hello, balls! (release)\n"); #endif - printf("Program exit as expected\n"); + print("Program exit as expected\n"); return 0; } diff --git a/oogabooga/oogabooga.c b/oogabooga/oogabooga.c index f4a4799..d40ef60 100644 --- a/oogabooga/oogabooga.c +++ b/oogabooga/oogabooga.c @@ -1,4 +1,14 @@ +#if !defined(DEBUG) && !defined(RELEASE) + +#ifdef _DEBUG +#define DEBUG +#elif defined(NDEBUG) +#define RELEASE +#endif + +#endif + #ifdef _WIN32 #include #define OS_WINDOWS diff --git a/oogabooga/os_interface.c b/oogabooga/os_interface.c index 20116f8..dedee8b 100644 --- a/oogabooga/os_interface.c +++ b/oogabooga/os_interface.c @@ -220,7 +220,7 @@ void print_va_list_buffered(const string fmt, va_list args) { } // context.allocator (alloc & dealloc) -void print(const string fmt, ...) { +void prints(const string fmt, ...) { va_list args; va_start(args, fmt); print_va_list_buffered(fmt, args); @@ -237,7 +237,11 @@ void printf(const char* fmt, ...) { va_end(args); } - +#define FIRST_ARG(arg1, ...) arg1 +#define print(...) _Generic((FIRST_ARG(__VA_ARGS__)), \ + string: prints, \ + default: printf \ + )(__VA_ARGS__) /// /// // Memory diff --git a/oogabooga/string.c b/oogabooga/string.c index fd6c218..90a2bb6 100644 --- a/oogabooga/string.c +++ b/oogabooga/string.c @@ -51,7 +51,7 @@ typedef struct string { void push_temp_allocator(); #define cstr const_string -#define const_string(s) (string){ length_of_null_terminated_string(s), (u8*)s } +#define const_string(s) ((string){ length_of_null_terminated_string(s), (u8*)s }) inline u64 length_of_null_terminated_string(const char* cstring) { u64 len = 0; diff --git a/oogabooga/tests.c b/oogabooga/tests.c index 1343f5d..8e32249 100644 --- a/oogabooga/tests.c +++ b/oogabooga/tests.c @@ -299,7 +299,7 @@ void test_strings() { // Test print and printf (visual inspection) printf("Expected output: Hello, World!\n"); - print(const_string("Hello, %s!\n"), const_string("World")); + print("Hello, %s!\n", const_string("World")); printf("Expected output: Number: 1234\n"); print(const_string("Number: %d\n"), 1234);