diff --git a/book/samples/03_variadic_macro.c b/book/samples/03_variadic_macro.c new file mode 100644 index 0000000..c13014e --- /dev/null +++ b/book/samples/03_variadic_macro.c @@ -0,0 +1,16 @@ +#include // printf + +#define MARKDOWN_HEADER "|Level|File|Function|Line|Message|\n|:-|:-|:-|-:|:-|\n" + +#define log_log(LEVEL, MESSAGE, ...) \ + printf("|" LEVEL "|`" __FILE__ "`|`%s`|%i|" MESSAGE "\n", __func__, __LINE__ __VA_OPT__(,) __VA_ARGS__) + +#define log_debug(MESSAGE, ...) log_log("DEBUG", MESSAGE __VA_OPT__(,) __VA_ARGS__) +#define log_error(MESSAGE, ...) log_log("ERROR", MESSAGE __VA_OPT__(,) __VA_ARGS__) + +int main(int ac, char** av) +{ + printf(MARKDOWN_HEADER); + log_debug("Hello world !"); + log_error("Failed to open %s: %s", "bar.csv", "no such file"); +}