Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!lll-winken!uunet!mitel!sce!cognos!dgbt!lew From: lew@dgbt.uucp (Lew Stelmach) Newsgroups: comp.lang.c Subject: Microsoft C 5.1 - bug Message-ID: <1051@dgbt.uucp> Date: 11 Apr 89 13:52:08 GMT Reply-To: lew@dgbt.crc.dnd.ca (Lew Stelmach) Organization: The Communications Research Centre, Ottawa, CANADA Lines: 75 The following program compiles successfully on Microsoft C5.1, Microsoft Quick C 2.0, TurboC, DEC VAX Ultrix C, Sun Unix C, and other compilers. However, it does not run correctly when compiled using Microsoft C5.1. Note that it runs correctly on Microsoft Quick C 2.0. The program allocates a ring of pointers. The correct form of the output is shown below the program listing. The actual values will differ from machine to machine . The pattern is what matters. The critical feature to look for is that the right-most column of addresses (pointer values) should increase if the program runs correctly. In MSC5.1 these numbers stay constant. I compiled with the medium memory (cl -AM). /*-------------------------------------------------*/ #include struct Block{ struct Block *fwp; }; main () { struct Block *at,*aa; char *c; int i; at=NULL; for(i=0;i<10;i++){ aa=(struct Block *)malloc(sizeof(struct Block)); if(!aa)break; if(at){ aa->fwp=at->fwp; at->fwp=aa; } else { at=aa; aa->fwp=aa; } printf("at=%d aa=%d at->fwp=%d aa->fwp=%d\n", at,aa,at->fwp,aa->fwp); } } /* --------------------------------------------------*/ Sample output (correct version). In the incorrect (MSC5.1) version the rightmost column would be 5124 all the way down. at=5124 aa=5124 at->fwp=5124 aa->fwp=5124 at=5124 aa=5132 at->fwp=5132 aa->fwp=5124 at=5124 aa=5140 at->fwp=5140 aa->fwp=5132 at=5124 aa=5148 at->fwp=5148 aa->fwp=5140 at=5124 aa=5156 at->fwp=5156 aa->fwp=5148 at=5124 aa=5164 at->fwp=5164 aa->fwp=5156 at=5124 aa=5172 at->fwp=5172 aa->fwp=5164 at=5124 aa=5180 at->fwp=5180 aa->fwp=5172 at=5124 aa=5188 at->fwp=5188 aa->fwp=5180 at=5124 aa=5196 at->fwp=5196 aa->fwp=5188 Do you have an explanation or any comments? Lew Stelmach --------------------------------------------------------------------- Lew Stelmach, Ph.D. Communications Research Centre P.O. Box 11490, Station H (613) 998 2005 Ottawa, Ontario, K2H 8S2, Canada BITNET: lew@doccrc.bitnet Others: lew@dgbt.crc.dnd.ca ---------------------------------------------------------------------