473,801 Members | 2,256 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

printf("%hhd",8 9);

printf("%hhd",8 9);/*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
7 5237
"Rajesh S R" wrote:
printf("%hhd",8 9);/*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
On Apr 9, 8:56 am, "osmium" <r124c4u...@com cast.netwrote:
"Rajesh S R" wrote:
printf("%hhd",8 9);/*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
"Rajesh S R" <SR**********@g mail.comwrites:
printf("%hhd",8 9);/*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_Keit h) 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
"osmium" <r1********@com cast.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_Keit h) 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
"Keith Thompson" <ks***@mib.orgw rote in message
news:ln******** ****@nuthaus.mi b.org...
"osmium" <r1********@com cast.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.J. Plauger" <pj*@dinkumware .comwrites:
"Keith Thompson" <ks***@mib.orgw rote in message
news:ln******** ****@nuthaus.mi b.org...
>"osmium" <r1********@com cast.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_Keit h) 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
"Keith Thompson" <ks***@mib.orgw rote in message
news:ln******** ****@nuthaus.mi b.org...
"P.J. Plauger" <pj*@dinkumware .comwrites:
>"Keith Thompson" <ks***@mib.orgw rote in message
news:ln******* *****@nuthaus.m ib.org...
>>"osmium" <r1********@com cast.netwrites:
"Rajesh S R" wrote:
printf("%hh d",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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
13402
by: albert.neu | last post by:
To what extent does Microsoft Visual C++ also called: VC++ also called: Microsoft (R) 32-bit C/C++ Optimizing Compiler support C99? VC++ compiles either in C mode (which is def. *not* C99!):
0
9698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9558
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10524
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10298
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10055
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4265
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2963
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.