Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site sdcsvax.UUCP Path: utzoo!watmath!clyde!burl!mgnetp!ihnp4!houxm!mhuxl!ulysses!allegra!mit-eddie!genrad!decvax!ittvax!dcdwest!sdcsvax!greg From: greg@sdcsvax.UUCP Newsgroups: net.lang.c Subject: Randomly-Signed Character Variables Message-ID: <30@sdcsvax.UUCP> Date: Thu, 6-Sep-84 13:21:04 EDT Article-I.D.: sdcsvax.30 Posted: Thu Sep 6 13:21:04 1984 Date-Received: Wed, 12-Sep-84 03:19:50 EDT Organization: EECS Dept. U.C. San Diego Lines: 33 Keywords: sign extension, character variables 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@sdcsvax.UUCP or Greg@nosc.ARPA