Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!ncar!oddjob!mimsy!haven!trantor.umd.edu!louie From: louie@trantor.umd.edu (Louis A. Mamakos) Newsgroups: comp.sys.amiga.tech Subject: Lattice C bug: unsigned short array subscript sign extended; TeX Keywords: TeX, Lattice C Message-ID: <2993@haven.umd.edu> Date: 19 Aug 88 03:29:28 GMT Sender: news@haven.umd.edu Reply-To: louie@trantor.umd.edu (Louis A. Mamakos) Organization: University of Maryland, College Park Lines: 89 I've discovered this bug in Lattice C, version 4.01 and reported it to the Lattice customer support folks. It seems that if you subscript an array (or pointer, same thing) with an unsigned short, the subscript is still sign extended. This makes it impossible to have a subscript greater than 32K using unsigned shorts. The Lattice guy reproduced the problem, and thought that there would be another patch to version 4 of the compiler before the next major release (which is 5.0, I think along with the symbolic debugger). Anyway, simple test program: int *array; unsigned short us; func() { int i; i = array[us]; return i; } compile this with or without -b0, and look at the object file created with OMD. You'll see an EXT.L; bad news. LATTICE OBJECT MODULE DISASSEMBLER V2.00 Amiga Object File Loader V1.00 68000 Instruction Set EXTERNAL DEFINITIONS _foo 0000-00 _array 0000-02 _us 0004-02 SECTION 00 "test.o" 00000020 BYTES int *array; unsigned short us; foo() { 0000 4E55FFFC LINK A5,FFFC 0004 BFEC 0000-XX.2 CMPA.L __base(A4),A7 0008 6500 000A 0000-XX.1 int i; i = array[us]; 000C 302C 0004-02.2 MOVE.W 02.00000004(A4),D0 0010 48C0 EXT.L D0 <=== WRONG! === 0012 E580 ASL.L #2,D0 0014 206C 0000-02.2 MOVEA.L 02.00000000(A4),A0 0018 D1C0 ADDA.L D0,A0 001A 2010 MOVE.L (A0),D0 return i; 001C 4E5D UNLK A5 001E 4E75 RTS SECTION 01 "__MERGED" 00000000 BYTES SECTION 02 "__MERGED" 00000008 BYTES Extra bonus bug: When compiling a module with -b0 (absolute reference, rather than off of A4), the compiler will not allow you to have more than 64K of data declared in the BSS section (at least). It seems logical to prevent you from doing with if you don't specify -b0, since it would be difficult to reference the data, but doesn't make sense otherwise. This makes my port of TeX-in-C have to malloc() the various arrays; the first bug makes it difficult to create non-trivial documents using LaTeX with a 32K memory size. Once there problems are worked out, I'll probably distribute my port, along with the dvi-to- postscript translator for the amiga. My port of TeX doesn't run as fast as AmigaTeX does, nor does it have loop mode and all that good stuff, but its free. It also probably won't fit on a 512K machine either. I suppose that if I really begin to do serious TeX work, I'll probably spend the $200 and buy AmigaTeX. If the demo version on one of the Fish disks is any indication, its is a wonderful product. Once I hear back from Lattice, I'll follow up with what they've decided to do. Louis A. Mamakos WA3YMH Internet: louie@TRANTOR.UMD.EDU University of Maryland, Computer Science Center - Systems Programming