473,378 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

expected printf() output

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
8 2163
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


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
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
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
"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
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
"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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: aditya | last post by:
Hi all, Can body please me that why the following code in not working as expected.Basically,my aim was to shift the control from one function to another as soon as I presses Control-c keys. In...
8
by: aditya | last post by:
hi, Can anybody please tell me that how the following printf(...) statement works- main(){ int d=9; printf("%d",printf("%d")); return 0;
9
by: Eric Lilja | last post by:
Hello, I have two code snippets I want you to look at. My program compiles without warnings (warning level set to max, gcc 3.4.3) with either snippet but the latter one causes a segfault at...
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
29
by: whatluo | last post by:
Hi, c.l.cs I noticed that someone like add (void) before the printf call, like: (void) printf("Timeout\n"); while the others does't. So can someone tell me whether there any gains in adding...
8
by: Gregc. | last post by:
Hi Sorry to bother you gusy with such a basic question, but I am working on a conversion program. I've got most of it down, but I am having trouble with the output: *Dollar Conversion...
4
by: pai | last post by:
Hi , Can any one tell me how this statement of printf is behaving . how the last digit is printed int a=2,b=4,c=7; printf("%d",printf("%d %d:",a,b)); //answer to this was 2 4:3
6
by: MikeC | last post by:
Folks, Can the width specifier be used in a printf() text string? If I execute... printf("%4s", ".........."); it prints ten dots. If I execute
11
AmberJain
by: AmberJain | last post by:
Hello everyone, Newbie here, PLZ HELP....... This is what I coded (it's very very simple, still I'm facing problem with this code) --------->...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.