[comp.lang.c] signed chars

carroll@snail.CS.UIUC.EDU (12/09/87)

	I'm having some problems with code that need signed characters (it's
originally from a vax). Unfortunately, the machine I am on has unsigned
characters. I have not been able to find any way in C to tell the compiler to
use the characters as signed. I know that the hardware can support them, but
is there any generic way to force things to be signed? K&R has the "unsigned"
reserved word, but "signed" is not. Any help would be appreciated.

	We are running SysVR3 on AT&T 3b2's, standard C.


Alan M. Carroll		amc@woodshop.cs.uiuc.edu	carroll@s.cs.uiuc.edu
...{ihnp4,convex}!uiucdcs!woodshop!amc
Quote of the day :
	"I've consulted all the sages I could find in Yellow Pages,
	 but there aren't many of them" - AP & EW

karl@haddock.ISC.COM (Karl Heuer) (12/10/87)

In article <10700010@snail> carroll@snail.CS.UIUC.EDU writes:
>I'm having some problems with code that need signed characters (it's
>originally from a vax).  Unfortunately, the machine I am on has unsigned
>characters.

In ANSI C, there is a keyword "signed" that does what you want.  In pre-ANSI,
the best way is to use a macro when you need sign-extension.  Assuming 8-bit
chars, the following is probably as good as anything.

#if CHARS_ARE_SIGNED
#define sxt(c) ((int)(c))
#else
#define sxt(c) ((int)(unsigned char)((c) + 0x80) - 0x80)
#endif

jal@occrsh.ATT.COM (J_Allen_Schones) (12/12/87)

In article <10700010@snail> carroll@snail.CS.UIUC.EDU writes:
>
>	I'm having some problems with code that need signed characters (it's
>originally from a vax). Unfortunately, the machine I am on has unsigned
>characters. 
[ A few lines deleted to keep inews happy ]
>
>	We are running SysVR3 on AT&T 3b2's, standard C.
>

As far as I can tell, there is no way to support signed chars on the 3BXX*
line of computers.  I use short ints when a signed chars is needed, but then
you must check the source to make sure that the program doesn't depend upon
the allowable range of chars.


I      F
 N      I
  E      L
   W      L
    S      E
            R-- 
J. Allen Schones -- AT&T Technologies -- Oklahoma City Works
 PHONE: (405) 491-4950
  UUCP: ihnp4!occrsh!jal
DOMAIN: jal@occrsh.ATT.COM