Microsoft C 5.1 - bug

Lew Stelmach lew at dgbt.uucp
Tue Apr 11 23:52:08 AEST 1989


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 <stdio.h>

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 at doccrc.bitnet 
Others: lew at dgbt.crc.dnd.ca        
---------------------------------------------------------------------



More information about the Comp.lang.c mailing list