microsoft / sfs-client

Simple File Solution (SFS) Client
MIT License
15 stars 13 forks source link

Add a compile-time check in Windows for logging macros #141

Open arthuraraujo-msft opened 8 months ago

arthuraraujo-msft commented 8 months ago

Suggestion by @shishirb-MSFT:

We can add a "(void)(0 && printf(format, __VA_ARGS__))" as the first line of the logging macros.

The expression is short-circuited by '0 &&' such that no runtime call is made. It will also do a compile-time check of the arguments.

arthuraraujo-msft commented 8 months ago

Did some testing:

LOG_INFO(handler, "%d", string_arg);

I got

warning C4477: 'printf' : format string '%d' requires an argument of type 'int', but variadic argument 1 has type 'const char *'

For

LOG_INFO(handler, "%s %d", string_arg);

warning C4473: 'printf' : not enough arguments passed for format string