Randomly-Signed Character Variables

greg at sdcsvax.UUCP greg at sdcsvax.UUCP
Fri Sep 7 03:21:04 AEST 1984


Recently there was a discussion as to whether "char" variables should be
signed or unsigned.  After some debate on the subject, the consensus was
that the choice should be whichever is "most optimal" for the architecture
involved.

I don't want to add fuel to that controversy, but I have an interesting
variant on that topic: suppose neither choice is optimal all the time?
In particular, we have an architecture which, for reasons not relevant
here, is asymmetric with respect to sign-extension on characters.  If the
character value is referenced directly via a pointer (or actually, any
calculation that produces a pointer directly to the variable) it is more
efficient to access the variable as signed.  At all other times, it is
more efficient to access the variable as unsigned.

OK, what's the choice?  Should our characters be signed or unsigned?  Or
should we use the "most optimal" rule and have the characters be signed
or unsigned depending upon the type of access?  We are all aware of the
portability problems associated with assuming one or the other; what will
happen if char variables are randomly sign-extended?  In other words, does
a portable program assume that char variables are consistent in their
sign-extension?

Note that if consistency is desired, the "most optimal" choice will vary
with the application.  If lots of references are made to char variables
via pointers, the choice will be sign-extended chars; if lots of references
are made to ordinary variables (or anything requiring an offset from a
pointer), the choice will be unsigned chars.  Which access type predominates?

I'd appreciate any thoughts you might have on this issue.  Are there any
C gurus out there who can offer any enlightenment?  What does the emerging
C standard have to say on the subject?
-- 
-- Greg Noel, NCR Torrey Pines       Greg at sdcsvax.UUCP or Greg at nosc.ARPA



More information about the Comp.lang.c mailing list