Bug in handling of "1$", "2$" in printf format

Keith Thompson Keith.S.Thompson@gmail.com
Sat Dec 7 02:16:37 GMT 2024


The use of "1$", "2$" et al in printf format specifiers is a
POSIX-specific feature.

On Cygwin (newlib) this is handled correctly in most cases, but one
example I tried misbehaves.
The output is correct on other implementations, including glibc and
musl on Ubuntu.

This C program:

#include <stdio.h>
int main(void) {
    long long a = 123456789876543210;
    double b=1.0/3;
    printf("a:%2$8.8lld b:%1$10.2g\n", b, a);
}

should produce this output:

a:123456789876543210 b:      0.33

Under Cygwin (fully updated), with "gcc c.c -o c && ./c", the output is:

a:140732550844138 b:  7.1e-315


More information about the Cygwin mailing list