Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.lang.c Subject: Re: Int and Char Message-ID: <2617@umcp-cs.UUCP> Date: Fri, 25-Jul-86 20:34:55 EDT Article-I.D.: umcp-cs.2617 Posted: Fri Jul 25 20:34:55 1986 Date-Received: Fri, 25-Jul-86 22:12:36 EDT References: <3250@jhunix.UUCP> Reply-To: chris@maryland.UUCP (Chris Torek) Organization: University of Maryland, Dept. of Computer Sci. Lines: 41 In article <3250@jhunix.UUCP> ecf_eprm@jhunix.UUCP (Paul R Markowitz) writes: >Chars are NOT SIGNED, there is no char called -1. Whether characters are signed or not is compiler-dependent. X3J11 says so; and even K&R says so (p. 40). >If you want a variable that takes on negative values, use a short. Or, optionally, a typedef and/or a sign-extension macro: /* * types.h: system dependent types. * * Turn on the appropriate things for your system. */ /* compiler error until installer adjusts this */ THIS FILE WAS NOT SET UP FOR YOUR SYSTEM YET! /* a small integer, signed */ /* typedef char smallint; */ /* typedef short smallint; */ /* take a number, treat as eight bits, and sign extend */ /* #define Sign8(c) ((int)(char)(c)) */ /* use this one on Suns to avoid a compiler bug with constants */ /* this also works on 32 bit machines with sign extending `>>' */ /* #define Sign8(c) (((c) << 24) >> 24) */ /* #define Sign8(c) ((c) & 0x80 ? (c) - 0x100 : (c)) */ Finally, for X3J11 C: /* typedef signed char smallint; */ /* #define Sign8(c) ((int)(signed char)(c)) */ -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu