Path: utzoo!attcan!uunet!samsung!sdd.hp.com!ucsd!helios.ee.lbl.gov!pasteur!ames!uhccux!munnari.oz.au!sirius.ucs.adelaide.edu.au!sirius.ua.oz.au!rfrost From: rfrost@spam.ua.oz.au (Richard Frost) Newsgroups: comp.sys.ibm.pc.programmer Subject: Bug in TC2.0 Message-ID: Date: 3 Jun 90 14:14:39 GMT Sender: news@ucs.adelaide.edu.au Distribution: comp.sys.ibm.pc.programmer Organization: Dept. of Stats Pure & Appl. Maths, Adelaide University Lines: 61 X-Local-Date: 3 Jun 90 07:14:39 PDT I have found what I think is a bug in version 2.0 of the Turbo C compiler. I am a K&R C programmer from some time back and have not read the full specs on ANSI C so I may be wrong. Bug Description: ================ Consider 2 separately compiled C modules "A.c" and "B.c" which share an array which is altered by a function in "B.c". The 2 modules look like: A.c: B.c: ==== ==== extern void testfn(void); char Test[] = {0xB0,0xB0,0xB0}; extern char *Test; main(int argc, char *argv[]) void testfn(void) { { ... ... testfn(); Test[1] = 'A'; *(Test+2) = 'B'; } } When testfn() is called in main() it returns without altering the array Test, however if the external reference to the array in B.c is written as "extern char Test[]" then the function succeeds in altering the array Test. After looking at the assembly code produced, if the orignal external reference is used when the code "Test[1]='A';" is executed, TC produces code which dereferences Test as though it is a pointer to a pointer to char thus giving the address 0xB0B0 (which are the chars in the initialized array) and then adding 1 and assigning to that address. (Note: incorrect code is also produced for the other array access : *(Test+1) = 'B'; ) Correct assembly is produced when the other external reference is used, ie "extern char Test[];" when the array is accessed in both manners shown. I would like to know if this is really a bug, I think it IS according to K&R rules. Has anyone else had similar problems?. -- ______________________________________________________________________________ _ ___ | Email Address: rfrost@spam.ua.oz.au I) I_ | I\ ichard I rost | FidoNet (ADAM LINK BBS): 3:680/805 Richard Frost ---------------------+-------------------------------------------------------- Bewildered Earth Scientist: "How do you re-wire alien equipment like that??" Dr. Who: "Its easy when you've had 900 years experience in alien technology." ______________________________________________________________________________