char buf[10];
int counter, x = 0;
snprintf (buf, sizeof buf , "%.100d%n", x, &counter);
printf("Counter: %d\n", counter)
I am learning about precision with printf. With %.100d%n, the precision here gives 100 digits for rendering x.
What I don't understand is why would the counter be incremented to 100, although only 10 characters are actually written to the buffer?
100you're getting is the size that is actually needed to printf the whole thing without truncation. Anyway I'd not use%nalltogether (it's not implemented on all platforms), but rather use the return value ofsnprintf.bufgcc -D__USE_MINGW_ANSI_STDIO=1%nbeing a security hole isn't really a strong argument. See also stackoverflow.com/questions/54957216/… It seems more like just another Microsoftian non-portable incompatibility.