Path: utzoo!mnetor!uunet!husc6!necntc!ima!haddock!karl
From: karl@haddock.ISC.COM (Karl Heuer)
Newsgroups: comp.lang.c
Subject: Re: signed chars
Message-ID: <1925@haddock.ISC.COM>
Date: 10 Dec 87 01:22:25 GMT
References: <10700010@snail>
Reply-To: karl@haddock.ima.isc.com (Karl Heuer)
Organization: Interactive Systems, Boston
Lines: 14
Summary: Until ANSI C, use a macro

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