expected printf() output

J

Johan Lindh

Where can I find a comprehensive test suite for printf()?
It seems like most implementations go wrong at sensitive spots, like
printf("#.0o",0) (which should print "0") printing nothing at all.

/J
 
M

Martin Ambuhl

Johan said:
Where can I find a comprehensive test suite for printf()?
It seems like most implementations go wrong at sensitive spots, like
printf("#.0o",0) (which should print "0") printing nothing at all.

No, it should print "#.0o", on the assumption that this is not the last
line of output, when the absence of a final '\n' makes its output
implementation-defined. Perhaps you need a test suite for
pseudo-C-programmers.
 
F

Fred L. Kleinschmidt

Johan said:
Where can I find a comprehensive test suite for printf()?
It seems like most implementations go wrong at sensitive spots, like
printf("#.0o",0) (which should print "0") printing nothing at all.

/J
I would expect that to print:
#.0o
and it does on my platforms.
 
J

Joona I Palaste

No, it should print "#.0o", on the assumption that this is not the last
line of output, when the absence of a final '\n' makes its output
implementation-defined. Perhaps you need a test suite for
pseudo-C-programmers.

The # was most probably a typo for %.
 
J

Johan Lindh

Johan said:
Where can I find a comprehensive test suite for printf()?
It seems like most implementations go wrong at sensitive spots, like
printf("#.0o",0) (which should print "0") printing nothing at all.

/J

Replying to myself to correct the typo:

printf("%#.0o",0)

/J
 
P

Peter Nilsson

Joona I Palaste said:
The # was most probably a typo for %.

No. The subtlety (or 'sensitive spot') is that the # flag will override the
zero precision to force an output when the value is 0.
 
J

Joona I Palaste

No. The subtlety (or 'sensitive spot') is that the # flag will override the
zero precision to force an output when the value is 0.

I beg your pardon? The way *I* see it, if there isn't a % character in
the format string, then the format string is printed literally, with
every character taken at its face value, with no special meanings like
"zero precision" or "flags".

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"As a boy, I often dreamed of being a baseball, but now we must go forward, not
backward, upward, not forward, and always whirling, whirling towards freedom!"
- Kang
 
P

Peter Nilsson

Joona I Palaste said:
I beg your pardon?

I hereby pardon you. ;)
The way *I* see it, if there isn't a % character in
the format string, then the format string is printed literally, with
every character taken at its face value, with no special meanings like
"zero precision" or "flags".

All that's true, but you're missing the _real_ issue (and you weren't the
only one). Johan didn't mistype the % as a # as you suggested, he simply
forgot to type the leading % altogether. [The subsequent correction bears
this out.]
 
P

Peter Nilsson

Johan Lindh said:
printf("%#.0o",0)

I'd shoot for 0u, but I'm afraid I can't answer your question. Apart from
the fact that the request is really off topic [try comp.compilers or a gnu
group], I don't know of any such test suites.

Plauger [Dinkumware] has a C++ test suite for sale, and I dare say he has a
C suite as well, but I'm sure I wouldn't be able to get the overdraft I'd
need to purchase it. [I'm sure they're not trivial things to build!]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top