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

printf("%hhd",89);

P: n/a
printf("%hhd",89);/*Assume char has 8 bits and is signed*/

Is it valid?

I know that it has been discussed in comp.std.c.

http://groups.google.co.in/group/com...941cbf/?hl=en#

But I want to know what was the conclusion that has been reached. It
is unusually long with 146 posts. Therefore it is hard to follow the
whole discussion.

Therefore I request the authors and those who followed the discussion
to summarize the conclusion that was reached so that it can be of some
help to the programmers.

I apologise for the inconvenience.

Thanks in advance for the reply.

Apr 9 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"Rajesh S R" wrote:
printf("%hhd",89);/*Assume char has 8 bits and is signed*/

Is it valid?

I know that it has been discussed in comp.std.c.

http://groups.google.co.in/group/com...941cbf/?hl=en#

But I want to know what was the conclusion that has been reached. It
is unusually long with 146 posts. Therefore it is hard to follow the
whole discussion.

Therefore I request the authors and those who followed the discussion
to summarize the conclusion that was reached so that it can be of some
help to the programmers.
See if you can tease the answer out of this Dinkumware link while you are
waiting for another answer.

http://www.dinkum.com/manuals/?manua...nt%20Functions
Apr 9 '07 #2

P: n/a
On Apr 9, 8:56 am, "osmium" <r124c4u...@comcast.netwrote:
"Rajesh S R" wrote:
printf("%hhd",89);/*Assume char has 8 bits and is signed*/
Is it valid?
I know that it has been discussed in comp.std.c.
http://groups.google.co.in/group/com...ad/thread/a656...
But I want to know what was the conclusion that has been reached. It
is unusually long with 146 posts. Therefore it is hard to follow the
whole discussion.
Therefore I request the authors and those who followed the discussion
to summarize the conclusion that was reached so that it can be of some
help to the programmers.

See if you can tease the answer out of this Dinkumware link while you are
waiting for another answer.

http://www.dinkum.com/manuals/?manua..._prin.html#Pri...
Thanks for the link osmium, a nice list to have.

Apr 9 '07 #3

P: n/a
"Rajesh S R" <SR**********@gmail.comwrites:
printf("%hhd",89);/*Assume char has 8 bits and is signed*/

Is it valid?

I know that it has been discussed in comp.std.c.

http://groups.google.co.in/group/com...941cbf/?hl=en#
Readers in the US should probably use "groups.google.com" rather than
"groups.google.co.in".
But I want to know what was the conclusion that has been reached. It
is unusually long with 146 posts. Therefore it is hard to follow the
whole discussion.

Therefore I request the authors and those who followed the discussion
to summarize the conclusion that was reached so that it can be of some
help to the programmers.
(I started that thread.)

I'm not sure that any firm conclusion was reached. As a practical
matter, it's going to work in any reasonable implementation. The
problem, I think, is that the standard says printf and friends are
variadic functions, but it doesn't actually say that they work the
same way as a function written in C using <stdarg.h>. It's reasonable
to assume that they do, but the standard doesn't explicitly say so.

As you say, it was a very long thread, and since it was several months
ago I don't remember everything that was discussed. The only real way
to determine whether a consensus was reached would be to read the
thread itself.

Also, note that the thread was in comp.std.c, not comp.lang.c, so I'm
not sure why you posted here. On the other hand, posting their most
likely either (a) wouldn't give you a definitive answer, or (b) would
spawn a lengthy thread rehashing the same arguments, possibly both.

The standard's wording is not 100% precise. The question, I suppose,
is how precise it really needs to be. It's been argued that the
wording of the standard has to be interpreted on the basis of common
sense; the problem is that not everybody's common sense is the same.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 9 '07 #4

P: n/a
"osmium" <r1********@comcast.netwrites:
"Rajesh S R" wrote:
>printf("%hhd",89);/*Assume char has 8 bits and is signed*/

Is it valid?

I know that it has been discussed in comp.std.c.

http://groups.google.co.in/group/com...941cbf/?hl=en#

But I want to know what was the conclusion that has been reached. It
is unusually long with 146 posts. Therefore it is hard to follow the
whole discussion.

Therefore I request the authors and those who followed the discussion
to summarize the conclusion that was reached so that it can be of some
help to the programmers.

See if you can tease the answer out of this Dinkumware link while you are
waiting for another answer.

http://www.dinkum.com/manuals/?manua...nt%20Functions
The debate was about a subtlety of the wording of the standard itself.
In a quick look over the dinkum.com page, I don't see anything that's
relevant to the question.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 9 '07 #5

P: n/a
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
"osmium" <r1********@comcast.netwrites:
>"Rajesh S R" wrote:
>>printf("%hhd",89);/*Assume char has 8 bits and is signed*/

Is it valid?

I know that it has been discussed in comp.std.c.

http://groups.google.co.in/group/com...941cbf/?hl=en#

But I want to know what was the conclusion that has been reached. It
is unusually long with 146 posts. Therefore it is hard to follow the
whole discussion.

Therefore I request the authors and those who followed the discussion
to summarize the conclusion that was reached so that it can be of some
help to the programmers.

See if you can tease the answer out of this Dinkumware link while you are
waiting for another answer.

http://www.dinkum.com/manuals/?manua...nt%20Functions

The debate was about a subtlety of the wording of the standard itself.
In a quick look over the dinkum.com page, I don't see anything that's
relevant to the question.
Dunno what the question is, but this excerpt *should* be relevant:

Conversion Argument Converted Default Pre-
Specifier Type Value Base cision
......
%hhd int x (signed char)x 10 1 added
with C99

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Apr 9 '07 #6

P: n/a
"P.J. Plauger" <pj*@dinkumware.comwrites:
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
>"osmium" <r1********@comcast.netwrites:
>>"Rajesh S R" wrote:
printf("%hhd",89);/*Assume char has 8 bits and is signed*/

Is it valid?

I know that it has been discussed in comp.std.c.

http://groups.google.co.in/group/com...941cbf/?hl=en#

But I want to know what was the conclusion that has been reached. It
is unusually long with 146 posts. Therefore it is hard to follow the
whole discussion.

Therefore I request the authors and those who followed the discussion
to summarize the conclusion that was reached so that it can be of some
help to the programmers.

See if you can tease the answer out of this Dinkumware link while you are
waiting for another answer.

http://www.dinkum.com/manuals/?manua...nt%20Functions

The debate was about a subtlety of the wording of the standard itself.
In a quick look over the dinkum.com page, I don't see anything that's
relevant to the question.

Dunno what the question is, but this excerpt *should* be relevant:

Conversion Argument Converted Default Pre-
Specifier Type Value Base cision
.....
%hhd int x (signed char)x 10 1 added
with C99
The issue is that the standard imposes certain specific requirements
on the arguments to printf(); it's not clear whether it has to treat
its arguments as if it were a user-written variadic function using
<stdarg.h>. For example, printf with a "%hd" format expects an
argument of type short, and "If any argument is not the correct type
for the corresponding conversion specification, the behavior is
undefined." Taken literally, that would imply that passing an int
argument, as in printf("%hd", 42) would invoke UB -- but if printf
acts like an ordinary variadic function, then printf("hd", 42) is
exactly equivalent to printf("%hd", (short)42).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 10 '07 #7

P: n/a
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
"P.J. Plauger" <pj*@dinkumware.comwrites:
>"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
>>"osmium" <r1********@comcast.netwrites:
"Rajesh S R" wrote:
printf("%hhd",89);/*Assume char has 8 bits and is signed*/
>
Is it valid?
>
I know that it has been discussed in comp.std.c.
>
http://groups.google.co.in/group/com...941cbf/?hl=en#
>
But I want to know what was the conclusion that has been reached. It
is unusually long with 146 posts. Therefore it is hard to follow the
whole discussion.
>
Therefore I request the authors and those who followed the discussion
to summarize the conclusion that was reached so that it can be of some
help to the programmers.

See if you can tease the answer out of this Dinkumware link while you
are
waiting for another answer.

http://www.dinkum.com/manuals/?manua...nt%20Functions

The debate was about a subtlety of the wording of the standard itself.
In a quick look over the dinkum.com page, I don't see anything that's
relevant to the question.

Dunno what the question is, but this excerpt *should* be relevant:

Conversion Argument Converted Default Pre-
Specifier Type Value Base cision
.....
%hhd int x (signed char)x 10 1
added
with C99

The issue is that the standard imposes certain specific requirements
on the arguments to printf(); it's not clear whether it has to treat
its arguments as if it were a user-written variadic function using
<stdarg.h>. For example, printf with a "%hd" format expects an
argument of type short, and "If any argument is not the correct type
for the corresponding conversion specification, the behavior is
undefined." Taken literally, that would imply that passing an int
argument, as in printf("%hd", 42) would invoke UB -- but if printf
acts like an ordinary variadic function, then printf("hd", 42) is
exactly equivalent to printf("%hd", (short)42).
Okay, now I understand the quibble. So the table entry above *is*
relevant, at least to the extent that it takes a position on the
matter. (Note Argument Type entry.) I will not further comment
on the pinhead area taken up by one dancing angel.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Apr 10 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.