Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!udel!mmdf From: bunnell@udel.edu (H Timothy Bunnell) Newsgroups: comp.os.minix Subject: (none) Message-ID: <23804@louie.udel.EDU> Date: 13 Sep 89 04:22:36 GMT Sender: mmdf@udel.EDU Lines: 42 The following short routine illustrates one version of a bug that I and several other folks have encountered (e.g., in both the recent ls.c postings). It was actually Earl Chew who fingered the problem in a response to patches to his ls. The bug crops up when a "static" is declared within a block that is not also the the start of a function. The example program compiles and goes thru asld without error messages, but prints garbage for the first printf while the second and third behave correctly. In other cases such as the recent ls postings, similar static declarations caused asld to punt with obscure multiple declaration errors. The effect of the bug is fairly obvious when looking at the compiler output. In the example program, two variables are created for the code within the scope of the if block. Neither one contains the four bytes that should initialize array3. Instead, both variables point to the static area containing the string arg for the printf. The compiler I'm using is the ACK compiler supplied with Minix 1.2 for PCs. I have the impression that other versions of the ACK compiler do not share this trait. This leads to a question: does anyone maintain a log of known and/or suspected compiler bugs? If so, perhaps it could be circulated periodically. Tim Bunnell ----------------------------cut here----------------------------------------- /* Illustrates a bug when compiled with the Minix 1.2 ACK compiler */ #include static char array1[] = {'a', 'b', 'c', 'd'}; main () { static char array2[] = {'1', '2', '3', '4'}; int bugpresent = 1; if (bugpresent) { static char array3[] = {'W', 'X', 'Y', 'Z'}; printf("Array3[1] = %c\n", array3[1]); } printf("Array2[1] = %c\n", array2[1]); printf("Array1[1] = %c\n", array1[1]); }