-
Notifications
You must be signed in to change notification settings - Fork 55
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
Unknown conversion type character 'b' in format #135
Comments
Let's start with:
|
But I will say that %b is not in the C standard, IIANM. So, if you do strict format checking - you are going to get a warning about that. |
As a minimal, macro free example a #include "printf/printf.h"
void putchar_(char character) {
(void)(character);
}
// Only for arm-none-eabi-gcc
void _exit(int status) {
(void)(status);
while (1) {
}
}
int main(void) {
printf_("%08b", 0xFF);
return 0;
} and compiled with regular x84_64 GCC version 11.2.0 will result in the following warnings:
Hmmn, this is unfortunate. I skimmed to format attribute pages of GCC but didn't find an alternative format specifier that would maybe cover it. This is was also the main reason why I opened this issue in the hope that there might be a undocumented workaround without disabling these checks. |
@KarlK90 : We can't "hold stick from both ends" - either we use only standard specifiers, or we don't require using standard specifiers... However - you could write a macro which suppresses the warning/error, I think. Have a look at |
Alright, the selective suppression of warnings solution was the one I would have liked to avoid. But that seems to be the only solution if I want to retain format warnings for all other cases. |
@KarlK90, You could always re-purpose the existing %o specifier in your own fork or implementation to output binary. Although if you deviate from standard behaviour, I'd recommend at least one compilation warning to alert future readers of your code. I've done this for both %o and %n, as the standard behaviour of these wasn't useful to me. |
@mickjc750 : Well, that is possible, but - unless Karl is the only user of the modified version, I would recommend against this, since changing the semantics of specifiers would be confusing for other developers. |
Yes this is unfortunately not really an option, the QMK user base is large with about 3000 keyboards (+users) only in the main repo. But that solution would work for me as single person. |
I did a bit of digging where these format arguments are actually implemented and low and behold |
@KarlK90 Thanks, that's good news :-) I did have one other idea. Depending on how many bits you need, you may be able to wrap your argument with a function that does some bit shifting, so that a %llo shows the same digits. You get 22 digits with %llo. |
Thanks, that is a neat trick for sure! Unfortunately we have binary output helpers up to 32 digits long... so that won't be applicable here here. |
@KarlK90 Oh, yes, I know that. But it'll be years before this propagates to all platforms. |
TLDR:
b
will be an offical format specifier with the upcoming C2X C standard, until then this warning can only be suppressed or some workaround applied as motioned in this thread.Hi @eyalroz,
I've encountered this format warning with
arm-none-eabi-gcc
version 10.3.1 on a Ubuntu 22.04 host using the latest develop branch ofprintf
. I'm trying to print a regular byte value in its binary representation using this macro, note thatxprintf
is just a redefine forprintf
.My question is now, can this warning be prevented with a different format attribute that covers this non-standard format specifier?
The whole error log is (this in in
qmk_firmware
if you are curious):The text was updated successfully, but these errors were encountered: