expected printf() output

Discussion in 'C Programming' started by Johan Lindh, Jan 30, 2004.

  1. Johan Lindh

    Johan Lindh Guest

    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
    Johan Lindh, Jan 30, 2004
    #1
    1. Advertising

  2. 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
    Martin Ambuhl, Jan 30, 2004
    #2
    1. Advertising

  3. 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
    Fred L. Kleinschmidt, Jan 30, 2004
    #3
  4. Martin Ambuhl <> 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 () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "Life without ostriches is like coffee with milk."
    - Mika P. Nieminen
    Joona I Palaste, Jan 31, 2004
    #4
  5. Johan Lindh

    Johan Lindh Guest

    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
    Johan Lindh, Jan 31, 2004
    #5
  6. "Joona I Palaste" <> wrote in message
    news:bvesd2$5ap$...
    > Martin Ambuhl <> 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
    Peter Nilsson, Jan 31, 2004
    #6
  7. Peter Nilsson <> scribbled the following:
    > "Joona I Palaste" <> wrote in message
    > news:bvesd2$5ap$...
    >> Martin Ambuhl <> 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 () ------------- 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
    Joona I Palaste, Jan 31, 2004
    #7
  8. "Joona I Palaste" <> wrote in message
    news:bvfv7r$m1j$...
    > Peter Nilsson <> scribbled the following:
    > > "Joona I Palaste" <> wrote in message
    > > news:bvesd2$5ap$...
    > >> Martin Ambuhl <> 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
    Peter Nilsson, Jan 31, 2004
    #8
  9. "Johan Lindh" <> wrote in message
    news:...
    > 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
    Peter Nilsson, Jan 31, 2004
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ben
    Replies:
    4
    Views:
    603
    Martin Ambuhl
    Jun 26, 2004
  2. whatluo

    (void) printf vs printf

    whatluo, May 26, 2005, in forum: C Programming
    Replies:
    29
    Views:
    1,229
  3. Logan Lee
    Replies:
    15
    Views:
    539
    Barry Schwarz
    Dec 19, 2007
  4. azza

    printf affects following printf/s

    azza, Oct 17, 2010, in forum: C Programming
    Replies:
    0
    Views:
    428
  5. guru
    Replies:
    8
    Views:
    268
Loading...

Share This Page