qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] Fix char signedness


From: Martin Guy
Subject: Re: [Qemu-devel] [PATCH] Fix char signedness
Date: Sat, 28 Oct 2006 11:46:05 +0100

gcc on ARM systems default to unsigned.  The C standard specifically
states that char is either signed or unsigned at the whim of the
implementor

Or, more to the point, at the behest of the machine architecture.
Having to generate code to sign-extend the hard way every time you do
char-integer promotion if the hardware doesn't do it automatically
would be long and inefficient, specially since it happens all the
time.
This has been a problem since the "All the world's a VAX" days, the
classic boob being

char c;
while ((c = getchar()) != EOF) {
    ...
}

of course, 255 always != -1 so it loops forever.
Check how many of your C primers get this wrong!
The flipside of that boob is that on a signed char architecture, the
loop will exit prematurely when it meets a 255 character.

These days instead, all the world's a 386 and anything different is broken...

24-bit integers, anyone? :)

  M




reply via email to

[Prev in Thread] Current Thread [Next in Thread]