Common malloc/free practice violates ANSI standard ?
Richard H. Gumpertz
rhg at cpsolv.UUCP
Sat Oct 21 15:17:59 AEST 1989
In article <1989Oct19.101306.16791 at twwells.com> bill at twwells.com (T. William Wells) writes:
>The standard requires that casting from (void*) to (OBJ*) and back
>give pointers that compare equal and point to the same object.
>Free will have no problems with it.
WRONG!
This is getting tiring. 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.
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 *. The standard SHOULD,
however, require this so the programmer does not have to keep an extra,
uncast, pointer around. Similar for realloc.
Fix the sentences defining free and realloc all is well again. Why can't people
accept that the standards process overlooked a small nit in the language? It
was an oversight. We should be grateful that it was pointed out and fix it in
the next revision. End of discussion.
--
==========================================================================
| Richard H. Gumpertz rhg at cpsolv.UUCP -or- ...!uunet!amgraf!cpsolv!rhg |
| Computer Problem Solving, 8905 Mohawk Lane, Leawood, Kansas 66206-1749 |
==========================================================================
More information about the Comp.lang.c
mailing list