aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Paland <marco@paland.com>2018-05-16 18:00:58 +0200
committerMarco Paland <marco@paland.com>2018-05-16 18:00:58 +0200
commit9351e5b1ac8e3871bf8a37fc3c24c120cf0e5614 (patch)
treef0e49e57b443e885d2f5d51a41c93b48f61cecba
parent24c460b977c014076821a36b2dae574893cebb85 (diff)
downloadprintf-9351e5b1ac8e3871bf8a37fc3c24c120cf0e5614.tar.gz
printf-9351e5b1ac8e3871bf8a37fc3c24c120cf0e5614.tar.bz2
printf-9351e5b1ac8e3871bf8a37fc3c24c120cf0e5614.zip
refactor(printf): use output function wrapping struct
-rw-r--r--printf.c10
1 files changed, 8 insertions, 2 deletions
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;
}