Path: utzoo!attcan!uunet!wuarchive!emory!mephisto!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!samsung!munnari.oz.au!csc!csc3.anu.oz!neptune!peterf From: peterf@arp.anu.oz.au (Peter Fletcher) Newsgroups: comp.sys.apollo Subject: Casting bug in C compiler 68K Rev 6.7(316) Message-ID: <1990Jul17.044917.20375@arp.anu.oz.au> Date: 17 Jul 90 04:49:17 GMT Organization: Automated Reasoning Project, ANU, Australia Lines: 34 There's a frustrating little bug in the Apollo 'c' compiler which has been there since at least before Rev 6.6. The following program should always output '65535', but if compiled with no optimization, it gets the answer wrong. >hera$ rm cbug ; make CC=/bin/cc cbug >/bin/cc cbug.c -o cbug >hera$ cbug >65280 >hera$ rm cbug ; make CC=/bin/cc CFLAGS=-O cbug >/bin/cc -O cbug.c -o cbug >hera$ cbug >65535 >hera$ cat cbug.c >main() > >{ > unsigned short a; > int off; > float scale; > unsigned short result; > > a = 0; > off = -1; > scale = 1.0; > > result = ((unsigned short)(((a)+off)*scale)); > > printf("%1u\n",result); >} >hera$ /com/cc -version >C compiler 68K Rev 6.7(316) peter fletcher