Signed/Unisgned chars (Was: What's a C expert?)

2014_5001 at uwovax.uwo.ca 2014_5001 at uwovax.uwo.ca
Tue Jun 27 20:12:08 AEST 1989


In article <2379 at uwovax.uwo.ca>, 2014_5001 at uwovax.uwo.ca writes:
> In article <1989Jun19.185803.4083 at marob.masa.com>, cowan at marob.masa.com (John Cowan) writes:
>> In article <6057 at microsoft.UUCP> paulc at microsoft.UUCP (Paul Canniff 2/1011) writes:
>>>[A expert in C] can tell why the following code
>>>prints "false" (on 8-bit char systems).
>>>
>>>	char x = 0xff;
>>>
>>>	if (x != 0xff)
>>>		printf("FALSE\n");
>> 
>> An expert in >portable< C, OTOH, knows that whether this code prints "FALSE"
>> (not "false") is system-dependent, since whether chars are signed or unsigned
>> is system-dependent.  In fact, my program "mch.c", which is compiled on a
>> given system to determine various system-dependent facts about it and print
>> them out as a set of #defines uses logic much like this to decide whether
>> chars are signed or unsigned.
>> 
> Howvwer in real C (ANSI C) chars are guaranteed signed.
> 
Sorry.  I was wrong, but the docs that came with my C compiler
said that ANSI guaranteed signed chars by default.  Thanx for
telling me of my error.  In fact the documentation says that
the compiler switched defaults to conform with ANSI.
(My compiler is turbo C).



More information about the Comp.lang.c mailing list