Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!rutgers!sri-spam!sri-unix!hplabs!hpcea!hpfcdc!hpcnoe!jason From: jason@hpcnoe.UUCP (Jason Zions) Newsgroups: net.lang.c Subject: Re: Signed char - What Foolishness Is This! Message-ID: <790009@hpcnoe.UUCP> Date: Sat, 18-Oct-86 15:08:03 EDT Article-I.D.: hpcnoe.790009 Posted: Sat Oct 18 15:08:03 1986 Date-Received: Tue, 21-Oct-86 22:03:10 EDT References: <8719@duke.duke.UUCP> Organization: HP Colorado Networks Division Lines: 40 jwg@duke.UUCP (Jeffrey William Gillette) / 6:26 am Oct 16, 1986 / > 1) Do other C compilers make 'char' a signed quantity by default? Oh, let's see. The PDP-11 and VAX chars are signed by default. There are doubtless many others; I believe 68000 defaults to signed as well. > 2) What possible justification is there for this default? You'll notice in the above list that I mentioned CPU types, rather than particular compilers. That's because of the answer to your question 2. A compiler may choose to make chars signed or unsigned depending upon which is more efficient. chars are indeed arithmetic objects; if they weren't, you couldn't freely intermix them with integers. The problem you're running into is an age-old one; the automatic conversion of a char to an int. If a char is signed, the conversion is a sign-extending one, resulting in a potentially negative int. If the char is unsigned, the conversion is (essentially) a bit-field copy, and the resulting int is always positive. K&R, chapter 2, page 40: The language does not specify whether variables of type *char* are signed or unsigned quantities. When a *char* is converted to an *int*, can it ever produce a *negative* integer? Unfortunately, this varies from machine to machine, reflecting differences in architecture. Have fun; this one bites everyone at least once... I've lost about a pound of flesh from a sensitive portion of my anatomy from being bitten so often. -- This is not an official statement of Hewlett-Packard Corp., and does not necessarily reflect the views of HP. It is provided completely without warranty of any kind. Lawyers take 3d10 damage and roll a saving throw vs. ego attack. Jason Zions Hewlett-Packard Colorado Networks Division 3404 E. Harmony Road Mail Stop 102 Ft. Collins, CO 80525 {ihnp4,seismo,hplabs,gatech}!hpfcdc!hpcnoe!jason