Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
arthuraraujo-msft opened this issue Mar 11, 2024 · 1 comment
Open

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

arthuraraujo-msft opened this issue Mar 11, 2024 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@arthuraraujo-msft
Copy link
Contributor

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 arthuraraujo-msft added the enhancement New feature or request label Mar 11, 2024
@arthuraraujo-msft arthuraraujo-msft added this to the Future milestone Mar 11, 2024
@arthuraraujo-msft
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant