Path: utzoo!utgpu!watmath!att!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!husc6!ogccse!blake!uw-beaver!fluke!dcd
From: dcd@tc.fluke.COM (David Dyck)
Newsgroups: comp.os.minix
Subject: PC minix compiler bug/question
Keywords: PC minix compiler bug zoo booz unsigned char casts
Message-ID: <10363@fluke.COM>
Date: 14 Aug 89 21:36:27 GMT
Sender: news@tc.fluke.COM
Organization: John Fluke Mfg. Co., Inc., Everett, WA
Lines: 48


I was trying to port zoo to PC minix, (so I first tried booz, the barebones 
zoo archive extractor), and I came across an expression that the
Minix compiler interprets differently than the other C compilers
I have access to.

Given
	char p[1]= {-1};
what does
	(unsigned char) *p
evaluate to?

On the Minix ibm-pc c compiler it is -1 but all other systems seem to evaluate
to 255.  
	How does you favorite compiler handle this?
	What should the correct C compiler produce?

In the following test program
------------------- cut here ------------------
char p[1]= {-1};
main()
{
printf("*p                   = %d\n", 
	*p);
printf("(unsigned char) *p   = %d\n", 
	(unsigned char) *p );
printf("* (unsigned char *)p = %d\n", 
	* (unsigned char *)p );
}
---------------- cut here -------------------

PC Minix prints out the following output

*p                   = -1
(unsigned char) *p   = -1
* (unsigned char *)p = 255

But Sun 4.0.3, Vax 4.3 BSD UNIX, and MSC 5.0.1 produce the following output:

*p                   = -1
(unsigned char) *p   = 255
* (unsigned char *)p = 255

            David Dyck
    Domain: dcd@tc.fluke.COM
     Voice: +1 206 356 5807
      UUCP: {uw-beaver,decwrl,microsof,sun}!fluke!dcd
     Snail: John Fluke Mfg. Co. / P.O. Box C9090 / Everett WA  98206