-funsigned-char option

Ian Lance Taylor iant@google.com
Mon Feb 21 06:30:00 GMT 2011


kevin diggs <diggskevin38@gmail.com> writes:

> 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?

Most machines have an instruction which loads a single byte from memory
into a register which is more than a single byte.  Some machines sign
extend the loaded value, some machines zero extend, some machines have
both kinds of instruction.  On machines which only have sign-extend or
zero-extend, that is a good choice to use for the default signedness of
char.

Ian



More information about the Gcc-help mailing list