Brynet-Inc wrote:OpenBSD's printf(3) calls the precision argument a digit string, and POSIX 1003.1-2008 calls it a decimal digit string.
The words 'digit' and 'string' here make a world of difference, IMHO, implying acceptable values between 0-9.
What specification calls it a decimal integer btw, ISO C?
Sorry, should have mentioned what I was quoting. It's the C99 spec indeed. You're right, in POSIX it sounds as if negative precision wasn't allowed. But it's an additional restriction that plain C doesn't seem to make (or at least C99, thanks for looking up C1x, fronty!).
Still, '-' after '.' should be ignored and the precision be treated as 0, OpenBSD does this.
No, there's nothing that says that invalid characters should be silently ignored. In this case '-' would be the conversion specifier and we would have undefined behaviour.
gerryg400 wrote:In the Posix spec. it says
A negative precision is taken as if the precision were omitted.
I think I misread it the first time and reading it again that is only meant to apply to precision specified with the '*'
Yes, having another look I think you could (and probably should) read it like that. In which case the spec just wouldn't say anything about negative precision in a format string. Probably another way to make it undefined behaviour.
I guess I should just remove these cases from my tests. In practice nobody will use it anyway, and I'm almost convinced now that it's undefined behaviour.
but my code treats negative or zero precision the same way, however the precision is specified
Zero precision is different from not specifying precision at all: printf("%.d", 0) prints nothing.