From 9351e5b1ac8e3871bf8a37fc3c24c120cf0e5614 Mon Sep 17 00:00:00 2001 From: Marco Paland Date: Wed, 16 May 2018 18:00:58 +0200 Subject: refactor(printf): use output function wrapping struct --- printf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'printf.c') diff --git a/printf.c b/printf.c index 0b94d4a..342d91c 100644 --- a/printf.c +++ b/printf.c @@ -105,7 +105,10 @@ static inline void _out_char(char character, char* buffer, size_t idx, size_t ma static inline void _out_fct(char character, char* buffer, size_t idx, size_t maxlen) { (void)idx; (void)maxlen; - ((void (*)(char character))buffer)(character); // buffer is the output fct pointer + typedef struct tag_out_fct_wrap_type { + void (*fct)(char character); + } out_fct_wrap_type; + ((out_fct_wrap_type*)buffer)->fct(character); // buffer is the output fct pointer } @@ -692,7 +695,10 @@ int oprintf(void (*out)(char character), const char* format, ...) { va_list va; va_start(va, format); - const int ret = _vsnprintf(_out_fct, (char*)out, (size_t)-1, format, va); + const struct tag_out_fct_wrap { + void (*fct)(char character); + } out_fct_wrap = { out }; + const int ret = _vsnprintf(_out_fct, (char*)&out_fct_wrap, (size_t)-1, format, va); va_end(va); return ret; } -- cgit v1.2.3