Q: "[W]hich platforms/C-standard-library implementations support "%b"? And - can I test for this support?"

A: glibc has supported %b integer conversion since version 2.35.

I don't have a list of which C libs support %b and which do not. I know that glibc (post ver 2.35) does, and I know that the picolibc does because I use them (i.e. I'm not a know-it-all :)

As far as testing, I guess there are two ways:

  1. For glibc, check the version as follows; e.g.:
ldd --version
ldd (Debian GLIBC 2.36-9+rpt2+deb12u3) 2.36
...
  1. For other C libraries, perhaps the best way is to compile a simple application in your preferred development environment; e.g.:
#include <stdio.h>
int main() {
    int int_val = 39;
    printf("binary value of int_val: %#b \n", int_val);

//  ANSWER: int_val = 0b100111 ; note no leading zeros

}
Answer from Seamus on Stack Overflow
🌐
Reddit
reddit.com › r/bash › potential incompatible change to printf's '%b' format specifier
r/bash on Reddit: Potential incompatible change to printf's '%b' format specifier
September 2, 2023 -

The people coming up with the next C language standard are proposing new printf() format specifiers %b and %B, to output integers as binary literals, i.e. 0b00010110, the binary representation of 22.

The section of the Bash manual describing the builtin printf command references the manual for the external printf program, printf(1); which itself references the manual for the C function printf(), printf(3). The Bash builtin printf command supports a bunch of C-language printf() format specifiers, so they just direct you to that documentation to see how those work.

However, the Bash builtin printf supports additional format specifiers, beyond those supported by the C-language printf(). One of those is %b, which in the case of Bash's printf, currently "causes printf to expand backslash escape sequences in the corresponding argument in the same way as echo -e."

A number of people from the Austin Group, the people behind the POSIX specification, emailed in to the bug-bash email list, where Bash development discussion takes place, saying that they would like a new POSIX standard to change the mandated behavior of the %b format specifier used by the command-line printf command, whether that's an external program or the Bash builtin, to mirror the behavior of this format specifier as used by the C printf() function in the upcoming C standard. They are recommending %#s, signifying an alternative string format, to take over the duties of the current %b. They do seem to be saying that they'd only change the standard in this way if they get buy-in from shell authors, though.

Chet Ramey, the Bash maintainer, really wasn't having it:

I don't have a problem adding %#s. I have a problem with POSIX not seeing that the printf builtin is not a direct parallel to the library function and forcing an incompatible change.

So, do scripts you write or maintain use the %b printf format specifier? What's your take on all this?

Discussions

c - printf's missing binary format specifiers: `%b` and `%B` - Stack Overflow
I'm using an Ubuntu 22.04 for some software development, and working with binary data. I recently found this announcement for glibc ver 2.35; it states that ver 2.35 incorporates the binary conversion format specifiers %b and %B: More on stackoverflow.com
🌐 stackoverflow.com
What is the format specifier for binary in C? - Stack Overflow
UPDATE: As of C23, the below function is no longer required. New format specifiers %b and %B have been added to printf() and friends to format integers as binary numbers—the former omitting any leading zeros and the latter including them (similar to %x and %X). More on stackoverflow.com
🌐 stackoverflow.com
Format specifiers in C
This has to do with the so-called "varargs" functions in C. Those are what allow you to specify a variable number (i.e. unknown number) arguments to a function, such as printf. For example, consider this code snippet: float a=1, b=2, c=3, e=4, f=5; int d=6, g=7; printf("%f %f %f %d %f %f %d\n", a, b, c, d, e, f, g); The printf function itself only knows that there is a const char * argument at the beginning (the format string), and a variable number of arguments afterwards. That's why you have to tell it, via the format strings, which arguments refer to which types. On most systems, a float and an int are different sizes, and printing them out is different as well. For example, printing a floating point number might involve printing a decimal sign "." and a fraction, whereas printing an integer only requires outputting characters 0-9. If you specify a wrong format string, most compilers will give you a warning. For example, int x = -123; printf("%u\n", x); In this example x is a (signed) int, but you gave the specifier %u (unsigned int). Most compilers nowadays will give you a warning. If you ignore the warning, printf will receive the int argument, and interpret those bytes as if they were an unsigned int. On most systems, this will print a very large unsigned value. More on reddit.com
🌐 r/learnprogramming
2
1
August 23, 2020
(Newbie) question pertaining C : format specifier "%pc"
The answers in the archived post are exactly right. A format specifier %pc does not exist. It's just %p followed by the letter c. The output it gives is an address No. If it was just %p, the output would just be an address. With %pc, the output is an address followed by the letter c. The trailing c is not part of the address, it's just a letter that's printed after the address because there was an errand c in the format string. More on reddit.com
🌐 r/learnprogramming
4
1
June 8, 2023
People also ask

What happens if the format specifier does not match the data type?
Using the wrong specifier can lead to undefined behavior or incorrect output. For example, using %d for a float can result in garbage values.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › format specifiers in c
Format Specifiers in C | Types and Usage with Examples
Can I use format specifiers for string manipulation in C?
Yes, format specifiers like %s are used to handle strings in both input and output. You can also limit the string size using a width specifier.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › format specifiers in c
Format Specifiers in C | Types and Usage with Examples
What are some common errors when using format specifiers in C with examples?
Common mistakes include mismatching specifiers, forgetting to include width for strings, or incorrectly formatting floating-point numbers, leading to errors or unexpected output.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › format specifiers in c
Format Specifiers in C | Types and Usage with Examples
🌐
Aticleworld
aticleworld.com › home › format specifiers in c programming language
Format specifiers in C Programming language - Aticleworld
July 28, 2021 - Format specifiers in C used for input and output purposes.Using format specifier compiler can understand what type of data is in input and output operation.
🌐
Educative
educative.io › blog › format-specifiers-in-c
Format Specifiers in C
Let’s learn how scan(f) works using the syntax below. ... format_specifier refers to the second parameter’s data type. The user specifies the data type of the variable for which the user will provide a value to the program so that it can be interpreted accordingly.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › format specifiers in c
Format Specifiers in C | Types and Usage with Examples
June 3, 2025 - In this tutorial, you’ll learn all commonly used format specifiers in C, including %d, %f, %c, %s, %u, %x, and more. We’ll also explain how they behave in input/output functions and what happens if you mismatch a format specifier with a data type.
🌐
Medium
medium.com › @eyobbasazinew › c-basics-740d20fa922b
C Basics. #6. Format specifiers in C | by Eyob | Medium
April 4, 2023 - C Basics #6. Format specifiers in C The format specifier is used during input and output. It is a way to tell the compiler what type of data is in a variable during taking input using scanf() or …
Find elsewhere
🌐
Unstop
unstop.com › home › blog › format specifiers in c — complete list with code examples (2026)
Format Specifiers in C — Complete List with Code Examples (2026)
May 19, 2026 - Format specifiers in C are placeholders used in printf() and scanf() to specify data types during input/output operations. The most commonly used format specifiers are: %d (integer), %f (float), %s (string), %c (character), %lf (double), and %p (pointer). Using the wrong format specifier can cause undefined behavior, incorrect output, or runtime errors.
🌐
W3Schools
w3schools.in › c-programming › format-specifiers
Format Specifiers in C - W3Schools
Format specifiers can be defined as the operators associated with the printf() function for printing the data referred to by any object or any variable. When a value is stored in a particular variable, you cannot print the value stored in the variable straightforwardly without using the format ...
Top answer
1 of 2
2

The reason for the discrepancy in your results is that the Raspberry Pi C SDK uses a different C library than the one on your Ubuntu system. Specifically, the picolibc library is used by the SDK for code compiled for a Pico target system. This would explain why you get no errors or warnings when the target is a Pico.

OTOH, glibc is the C library used for compilations targeted for Ubuntu. This is a bit of a guess, but I can imagine that since the first version of glibc to support the %b format was 2.35 (the version on your Ubuntu system), there was some unsettled business between gcc and glibc that resulted in a warning. I say this because earlier versions of glibc (e.g. ver 2.31) and gcc (ver 10.2.1) produced an error instead of a warning upon seeing the %b conversion in printf, and compile without error or warning w/ glibc ver 2.36 and gcc ver 12.2.

2 of 2
1

The Raspberry toolkit uses a different C compiler and C library, and seems to support the %b format at runtime (binary output) and compiler time (no warning).

Conversely, on the Ubuntu host, your C library supports the %b format (including the # option) as shown on the output, but the C compiler does not and reports a compile time warning.

The gcc warnings for printf and scanf argument consistency are produced at compile time by the compiler built-in analyser. The compiler does not use the C library for this so it may report a problem where the C library does support an extended format.

This inconsistency should be fixed with a more recent version of gcc, so you should either upgrade your system or install a more recent version of gcc manually. You can also check the behavior of clang.

You can disable these warnings, but they are very useful to avoid stupid mistakes, so you should do this on a case by case basis with pragmas.

🌐
SkillVertex
skillvertex.com › blog › format-specifiers-in-c
Format Specifiers In C
May 10, 2024 - In this article, we’ll explore what format specifiers are, what they do, and how to use them to make our programs work just the way we want. In C language, %c is the code used to specify the format for the char data type. It’s versatile because you can use it to both input and output char data in a specific format when working with C programs.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › using-variable-format-specifier-c
Using a variable as format specifier in C - GeeksforGeeks
May 29, 2017 - #include <stdio.h> int main() { float b = 6.412355; // using the format specifier %.*f // a = 3 will print value of b upto // 3 decimal places int a = 3; printf("%.*f\n", a, b); // a = 5 will print value of b upto // 3 decimal places a = 5; printf("%.*f\n", a, b); return 0; } Output:
🌐
Simplilearn
simplilearn.com › home › resources › software development › format specifiers in c: syntax and examples
Format Specifiers in C: Syntax and Examples
June 9, 2025 - Learn all about C format specifiers for efficient data display. Understand syntax and types for accurate formatting in your C programs.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_format_specifiers.htm
Format Specifiers in C
When you run the code, it will produce the following output − ... The value of the first variable replaces the first format specifier %d. Similarly, %f is substituted by the value of the percent variable.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › format-specifiers-in-c
Format Specifiers in C - GeeksforGeeks
2 weeks ago - They begin with the % symbol and are commonly used with functions like printf() and scanf(). Format specifiers tell the compiler how to interpret and process different data types.
🌐
Cplusplus
cplusplus.com › reference › cstdio › printf
Cplusplus
Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers.
🌐
W3Schools
w3schools.com › c › c_variables_format.php
C Format Specifiers
You can think of a format specifier as a placeholder that tells C what kind of value will be printed. A format specifier always starts with a percentage sign %, followed by a letter. For example, to output the value of an int variable, use the format specifier %d surrounded by double quotes (""), inside the printf() function:
🌐
Reddit
reddit.com › r/learnprogramming › format specifiers in c
r/learnprogramming on Reddit: Format specifiers in C
August 23, 2020 -

Hello, I am currently learning C and I was wondering what the point of format specifiers are. I understand what they do, but what is the point? If you declare a variable to be a float, why do you also have to specify the format in the printf() function? Isn't it still a float?

Thanks!