Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uunet!mcsun!unido!mcshh!hkr From: hkr@mcshh.hanse.de (Holger Kruse) Newsgroups: comp.sys.amiga.programmer Subject: Bug in SAS C 5.10a ? Keywords: SAS C,C,Bug Message-ID: <9195@mcshh.hanse.de> Date: 19 May 91 05:17:53 GMT Article-I.D.: mcshh.9195 Distribution: comp Lines: 62 I think I found a serious bug in SAS C 5.10a and some earlier versions. I reported the bug to SAS a month ago but have not got any answer yet. According to the manual, the size of a single subscript of an array may be larger than 32767 if long (32-bit) integers are used, this means that a declaration like int far a[2][40000]; is valid, if long integers are used. The compiler produces incorrect code, if the size of the second subscript is larger than 32767 and if the first subscript is indexed by a variable less than 32 bits long. Example: char far a[3][34000]; main() { short c=2; /*or: char c=2; */ a[c][0]=0; } After compiling ("LC filename") "OMD" produces the following disassembly: ... | 0002 7E02 MOVEQ #02,D7 | 0004 2007 MOVE.L D7,D0 \ this calculates a | 0006 C1FC 84D0 MULS.W #84D0,D0 / NEGATIVE offset !!! | 000A 41F9 0000 0000-01 LEA 01.00000000,A0 | 0010 D1C0 ADDA.L D0,A0 | 0012 4210 CLR.B (A0) ... Changing the assignment "a[c][0]=0" to "a[(long)c][0]=0" leads to a correct compilation result: ... | 0002 7E02 MOVEQ #02,D7 | 0004 2007 MOVE.L D7,D0 \ | 0006 48C0 EXT.L D0 \ this is OK | 0008 223C 0000 84D0 MOVE.L #000084D0,D1 / | 000E 4EBA 0000-XX.1 JSR __CXM33(PC) / | 0012 41F9 0000 0000-01 LEA 01.00000000,A0 | 0018 D1C0 ADDA.L D0,A0 | 001A 4210 CLR.B (A0) ... I could understand if SAS C reported an error in the above case, but there is no error message or warning. You simply get a GURU when you run the compiled program. Or maybe I am wrong and what I am doing is illegal in C ? Btw, the Unix TeX package contains lots of declarations like the above. So if you try to compile it on an Amiga, better be careful... Holger Kruse -------------------------------------+---------------------------------- Holger Kruse ! German BTX: 040526128800-0001 Zwijndrechtring 50, 2000 Norderstedt ! INTERNET: hkr@mcshh.hanse.de Germany Phone: +49 40 5261288 ! UUCP: uunet!mcshh.hanse.de!hkr