comp.lang.c
[Top] [All Lists]

Re: printf and cout

Subject: Re: printf and cout
From: Kenneth Brody
Date: Fri, 28 Mar 2008 13:53:09 -0400
Newsgroups: comp.lang.c

Richard Heathfield wrote:
> 
> jacob navia said:
[...]
> > That's what I am talking about. Obviously your example
> > will work.
> >
> > printf("%c",12345678);
> >
> > will not!
> 
> It is certainly true that it is not guaranteed to work. It is not
> guaranteed *not* to work, however. On systems with CHAR_BIT >= 24, it
> /will/ work (although heaven knows what character will be printed!).

Well, it depends on what you mean by "work".  According to 7.19.6.1p8,
on the part about the "%c" format:

    If no l length modifier is present, the int argument is converted
    to an unsigned char, and the resulting character is written.

Is it possible to "fail" when converting an int to unsigned char?  (Of
course you can lose bits, but can it "fail"?)

-- 
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody        | www.hvcomputer.com | #include              |
| kenbrody/at\spamcop.net | www.fptech.com     |    <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@xxxxxxxxx>



<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy