effect of free()
Shiping Zhang
ping at cubmol.BIO.COLUMBIA.EDU
Mon Aug 14 08:02:25 AEST 1989
When some space is allocated using calloc() or similar routines
and assigned to more than one point, for example as in following lines,
int *pt1,*pt2;
pt1=(int *)calloc(100,sizeof(int);
pt2=pt1;
then if free() is called using ONE of the points, say pt1, as its
argument, is the space pointed by pt1 really freed? Actually I have
two questions about this problem above.
First, can pt2 still be used as a valid point? In other words,
is pt2 still pointing to the location it is assigned to?
My answer to this question SEEMS yes according to some tests I made.
Second, would the space still pointed to by pt2 be reallocated
by other calls to calloc() or other similar funtions?
According to the document I read about free(), the space pointed
by the argument to free() is made available for further allocation,
though its contents are left unchanged. But it does not say what will
happen to the other points pointed to the same space.
Can anyone clarify this issue for me? Thanks.
-ping
More information about the Comp.lang.c
mailing list