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

Small printf with %lli prints 0 #91

Open
magnmaeh opened this issue May 5, 2024 · 0 comments
Open

Small printf with %lli prints 0 #91

magnmaeh opened this issue May 5, 2024 · 0 comments
Labels

Comments

@magnmaeh
Copy link
Collaborator

magnmaeh commented May 5, 2024

Our printf submodule can be configured to be much smaller by e.g., disabling a few features. Like so:

# Configure library to be as small as possible
set(SUPPORT_DECIMAL_SPECIFIERS false)
set(SUPPORT_EXPONENTIAL_SPECIFIERS false)
set(SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS false)
set(SUPPORT_WRITEBACK_SPECIFIER false)
set(SUPPORT_LONG_LONG false)
set(CHECK_FOR_NUL_IN_FORMAT_SPECIFIER false)

When SUPPORT_LONG_LONG is false, something like this will print 0.

uint64_t my_var = 99;
printf("My variable is: %lli\n", my_var);

The problem is that the compiler seems to interfere and automatically insert %lli in cases where the variable is 64 bits. E.g., if the user writes this, it will still print 0.

uint64_t my_var = 99;
printf("My variable is: %li\n", my_var);

The compiler does generate a warning, but I assume this can be a bit confusing still.

So a solution is either to keep SUPPORT_LONG_LONG on always (will increase code size) or see if it is possible to disable the compiler replacement.

@magnmaeh magnmaeh added the bug label May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant