Re: -funsigned-char option

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

 



On Sun, Feb 20, 2011 at 1:09 AM, ali hagigat <hagigatali@xxxxxxxxx> wrote:
> "-funsigned-char
> Each kind of machine has a default for what char should be. It is either like
> unsigned char by default or like signed char by default."
> I have copied part of gcc manual. What does the above line mean? I do
> not understand it.
>

Hi,

A char is almost universally 8 bits. But they can be treated as either
a signed, twos-complement value:

-128 => 1000 0000

0    => 0000 0000

127 => 0111 1111

or an unsigned value:

0   => 0000 0000

255 => 1111 1111


C code written using:

char some_char_used_for_some_silly_purpose;

will sometimes (usually?) be written assuming that it is one or the
other. These options allow you to override the compilers default
assumption.

The default the compiler chooses will depend on idiosyncrasies of the
processor (i.e. the signed compare instruction is faster or the
instruction is smaller (less bytes to represent it)). Or the jumps for
one or the other are smaller or faster. Or have a larger range. Or are
guaranteed to work during a full moon . ...

In reading through the internals doc, I stumbled across something I
had not realized:

Some machines have different compare instruction for signed and
unsigned values but only one 'set' of branches. I think powerpc is an
example (cmp crfD,L,rA,rB for signed and cmpl crfD,L,rA,rB for
unsigned). Others have one compare for both and branches for both
signed and unsigned results. Like x86s conditional jumps:

jb,jae,jbe,ja for unsigned, and

jl, jge, jle, jg for signed.

As far as I know, neither of these archs have any reason
(architecturally speaking) to choose one or the other. Anyone?

Anyone give an example where char defaults to unsigned (i.e. its
usually signed, right?)

kevin


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux