Malloc in Turbo C

Peter Gordon gordon at qfagus.OZ
Tue Feb 27 16:54:32 AEST 1990


Please tell me I'm doing something stupid.  The following code works on
Microsoft C and a MIPS/1000 runnung UNIX Sys V Release 4_0.
On Turbo C  (ver 2) it crashes after a variable number of frees.  I've tried
all memory models and far pointers and can't think of much else to
try.  Commonsense tells me that such a basic bug would not be
in Version 2, would some kind person point me in the right direction.
(I've tried the code on 8088, and 80386 machines, both with and without
floating point emulation.)
Peter Gordon.
------------------- cut here ------------------------------
echo "Extracting tst.c"
sed -e 's/^X//' > tst.c << END_OF_FILE
X#include	<stdio.h>
X#ifdef __TURBOC__
X#include	<alloc.h>
X#else
X#include	<malloc.h>
X#endif
X#include	<stdlib.h>
Xmain()
X{
X	char **head, **cp;
X	int	i;
X	head = (char **)malloc(200 * sizeof(char **));
X	for(cp = head, i = 0; i < 200; ++i, ++cp)
X	{
X		fprintf(stdout,"Freeing %d\n", i);
X		fflush(stdout);
X		free(cp);
X	}
X}
END_OF_FILE



More information about the Comp.lang.c mailing list