commom malloc/free practice breaks standard - author strikes back
Doug Gwyn
gwyn at smoke.BRL.MIL
Thu Oct 19 19:45:56 AEST 1989
In article <416 at cpsolv.UUCP> rhg at cpsolv.uucp (Richard H. Gumpertz) writes:
>4) If the implementor of malloc wants to return odd pointers, knowing that
>type-casting will round up (also UNUSUAL but legal), ...
NO, it is NOT legal! Sheesh.
>No sane compiler (actually, library) implementor should implement things that
>don't work with common coding style.
This is a useless criterion. Some common coding style is ERRONEOUS.
A C implementor should implement the language specified in the Standard,
providing whatever additional value seems appropriate. A programmer
should avoid asking of an implementation things that are not guaranteed
by the language standard. That is the "treaty point" that makes the
Standard useful.
>5) The appropriate changes to the standard would be in the sections on free
>and realloc. In particular, 4.10.3.2 should be expanded to indicate not just
>"a pointer earlier returned by the calloc, malloc, or realloc" but rather a
>pointer that may have been cast using "(void *) (any-type *)" from the value
>returned by calloc, malloc, or realloc. Similar changes to 4.10.3.4. Note
>that this change is really NEEDED in the standard anyway to allow the end-user
>to use the doubly-cast value for free rather than the original value.
Wrong, wrong, wrong. The Standard already says what was intended in
this regard. It did NOT intend for your interpretation to be applied.
In fact, what you're asking for can be deduced as a special case from
the existing specifications in the Standard; no additional wording is
necessary to enforce this constraint.
>Hence, I again recommend against the unusual rounding implementation.
I recommend against it because it is not standard conforming.
More information about the Comp.lang.c
mailing list