From 828ea0c2e238a962dcdfec02dfe45c73344f3b79 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Sun, 22 Aug 2021 12:22:41 +0200 Subject: [PATCH] made itoa and dbgln empty macros if no textIO is available to remove overhead --- kinclude/io.c | 12 ++---------- kinclude/io.h | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/kinclude/io.c b/kinclude/io.c index 021d1eb..67fce87 100644 --- a/kinclude/io.c +++ b/kinclude/io.c @@ -2,10 +2,6 @@ #ifdef TEXT_IO_ADDR -#ifndef TEXT_IO_BUFLEN -#error "When defining TEXT_IO_ADDR, please also provide TEXT_IO_BUFLEN, otherwise textIO won't work!" -#endif - void dbgln(char* text, int len) { while (len > TEXT_IO_BUFLEN) { @@ -68,11 +64,7 @@ char* itoa (int value, char* str, int base) #else -/* if no textIO module loaded, dbgln is a noop :( */ -void dbgln(char* text, int len){} -char* itoa (int value, char* str, int base) { - return str; -} +// this is included to prevent "error: ISO C forbids an empty translation unit [-Wpedantic]" +typedef int make_iso_compilers_happy; #endif - diff --git a/kinclude/io.h b/kinclude/io.h index 1009f59..38eb254 100644 --- a/kinclude/io.h +++ b/kinclude/io.h @@ -1,10 +1,26 @@ #ifndef H_IO #define H_IO +// if we have a textIO module +#ifdef TEXT_IO_ADDR + +#ifndef TEXT_IO_BUFLEN +#error "When defining TEXT_IO_ADDR, please also provide TEXT_IO_BUFLEN, otherwise textIO won't work!" +#endif + /* print a line to the debug textIO module */ void dbgln(char* text, int len); /* alphabet for itoa */ char* itoa (int value, char* str, int base); +#else + +// if we don't have textio, dbgln becomes an empty macro to save on cycles +#define dbgln(a,b) +// itoa just evaluates to the passes pointer +#define itoa(a,b,c) b + +#endif + #endif