Re: Printf question.
- From: Jack Klein <jackklein@xxxxxxxxxxx>
- Date: Fri, 30 Dec 2005 23:01:14 -0600
On Fri, 30 Dec 2005 20:56:02 GMT, Keith Thompson <kst-u@xxxxxxx> wrote
in comp.lang.c:
> Jack Klein <jackklein@xxxxxxxxxxx> writes:
> > On 30 Dec 2005 11:21:25 -0800, "praeiji" <spacecaps@xxxxxxxxx> wrote
> > in comp.lang.c:
> [...]
> >> unsigned char a = 200;
> >> char b = 200;
> >> printf( "%d %d", a, b );
> >>
> >> gives :
> >>
> >> 200, -56
> >>
> >> How comes? I didn't tell printf that the first argument was unsigned
> >> and it detected it on its own. It doesn't seem possible with varargs.
> >> How is it possible?
> [snip]
>
> > In the case of integer types of lesser rank than int, the "integer
> > promotions" occur. Since a signed int can hold the value 200, the
> > value in the unsigned char 'a' is converted to the int value 200.
>
> Correction: since a signed int can hold any value of type unsigned
> char, the value in the unsigned char 'a' is promoted to type int. The
> promoted type doesn't depend on the value that happens to be in the
> variable; it depends on which type can hold *any* possible value of
> the type.
Yes, thanks.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
.
- References:
- Printf question.
- From: praeiji
- Re: Printf question.
- From: Jack Klein
- Re: Printf question.
- From: Keith Thompson
- Printf question.
- Prev by Date: Re: How to stop reading a file?
- Next by Date: Re: Adding the ability to add functions into structures?
- Previous by thread: Re: Printf question.
- Next by thread: Structure size and binary format
- Index(es):
Relevant Pages
|