Re: [PATCH v2] printf: convert test_hashed into macro

From: Andy Shevchenko

Date: Mon Jan 19 2026 - 03:21:28 EST


On Fri, Jan 16, 2026 at 11:27:03AM -0500, Tamir Duberstein wrote:
> This allows the compiler to check the arguments against the __printf

__printf() since it takes parameters, OTOH it's an attribute at the end,
so I have no strong opinion on how to spell it.

> attribute on __test. This produces better diagnostics when incorrect

__test()

*This is reference to a function.

> inputs are passed.

...

> +/*
> + * This is a macro so that the compiler can compare its arguments to the
> + * __printf attribute on __test. This cannot be a function with a __printf
> + * attribute because GCC requires __printf functions to be variadic.

As per commit message remarks.

> + */
> +#define test_hashed(kunittest, fmt, p) \
> + do { \
> + char buf[PLAIN_BUF_SIZE]; \
> + plain_hash_to_buffer(kunittest, p, buf, PLAIN_BUF_SIZE); \
> + test(buf, fmt, p); \
> + } while (0)

Make sure you used tabs to indent the \:s.

...

The downside of a macro is a killing of compile-time type checks.

--
With Best Regards,
Andy Shevchenko