By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,507 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,507 IT Pros & Developers. It's quick & easy.

expected printf() output

P: n/a
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
Nov 14 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Johan Lindh wrote:
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.

--
Martin Ambuhl
Nov 14 '05 #2

P: n/a


Johan Lindh wrote:

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.

--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
Nov 14 '05 #3

P: n/a
Martin Ambuhl <ma*****@earthlink.net> scribbled the following:
Johan Lindh wrote:
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.


The # was most probably a typo for %.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Life without ostriches is like coffee with milk."
- Mika P. Nieminen
Nov 14 '05 #4

P: n/a
Johan Lindh wrote:
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
Nov 14 '05 #5

P: n/a
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bv**********@oravannahka.helsinki.fi...
Martin Ambuhl <ma*****@earthlink.net> scribbled the following:
Johan Lindh wrote:
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.


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.

--
Peter
Nov 14 '05 #6

P: n/a
Peter Nilsson <ai***@acay.com.au> scribbled the following:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bv**********@oravannahka.helsinki.fi...
Martin Ambuhl <ma*****@earthlink.net> scribbled the following:
> Johan Lindh wrote:
>> 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.


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.


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 (pa*****@cc.helsinki.fi) ------------- 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
Nov 14 '05 #7

P: n/a
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bv**********@oravannahka.helsinki.fi...
Peter Nilsson <ai***@acay.com.au> scribbled the following:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bv**********@oravannahka.helsinki.fi...
Martin Ambuhl <ma*****@earthlink.net> scribbled the following:
> Johan Lindh wrote:
>> 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.

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.


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.]

--
Peter
Nov 14 '05 #8

P: n/a
"Johan Lindh" <jo***@linkdata.getridofthis.se> wrote in message
news:40******@news.wineasy.se...
Johan Lindh wrote:
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.


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!]

--
Peter
Nov 14 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.