[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: gEDA-user: pcb crooked traces
On Wed, 2010-10-13 at 00:05 +0200, Karl Hammar wrote:
> Why does
>
> #include <stdio.h>
> int main(void) {
> char cc = 0xc4 // 'Ã' in latin1
> short str = cc;
> printf("0x%04hx\n", str);
> }
>
> print 0xffc4 instead of 0x00c4 ?
It is because 0xc4 is inserted into a "char", not an "unsigned char",
and is in binary:
1100 0100
Which is a _negative_ number. (-60 in decimal)
The compiler will (correctly) sign-extend the assigned value in str when
performing the type conversion.
I wasn't sure this was a question you already knew the answer two or
not.. but it is certainly a nice example of why you have to be careful
mixing different types, and signed-ness in general.
--
Peter Clifton
Electrical Engineering Division,
Engineering Department,
University of Cambridge,
9, JJ Thomson Avenue,
Cambridge
CB3 0FA
Tel: +44 (0)7729 980173 - (No signal in the lab!)
Tel: +44 (0)1223 748328 - (Shared lab phone, ask for me)
_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user