Common malloc/free practice violates ANSI standard ?
Doug Gwyn
gwyn at smoke.BRL.MIL
Tue Oct 24 00:22:04 AEST 1989
In article <423 at cpsolv.UUCP> rhg at cpsolv.uucp (Richard H. Gumpertz) writes:
-This is getting tiring.
I agree with THAT.
-The standard requires that casting OBJ * to void * and then back to
-OBJ * preserve the value. It does NOT (and intentionally so) require
-the reverse.
But it does when the storage pointed to by the void* is already OBJ-aligned,
such as for the (non-null) value returned by malloc().
-The description of free requires it to accept a value previously returned
-by malloc. It does not require it to accept a value that was returned from
-malloc and then cast to OBJ * and then back to void *.
Yes it does, but in more general terms, of which that is merely one
consequence.
More information about the Comp.lang.c
mailing list