malloc/free practice - more from the author

Brendan McKay bdm at anucsd.oz
Tue Oct 17 13:34:15 AEST 1989


Oops. I shouldn't have replied from home without my copy of the standard.
 
>> (D) Doug Gwyn  <gwyn at smoke.brl.mil>
>> No, we didn't -- any valid pointer can be converted to a pointer that
>> has less strict alignment and back, so that the result compares equal
>> to the original pointer,
 
> I can only find this rule for OBJ* -> void* -> OBJ* and OBJ* -> char* -> OBJ*.
> Am I missing a section?
 
Yes I was: Section 3.4.4.  Apologies to Doug.
 
===========================================================================
 
Most of you people don't understand my point.  You keep repeating that
malloc() is supposed to return a value with all-the-alignment-requirements-
of-any-type and that a subsequent cast to OBJ* won't change the-underlying-
address-or-whatever.  If I was implementing malloc()  [I'm not, by the way.],
I wouldn't do it any other way.  All I'm arguing is that the standard does
NOT require that.  The only alignment requirement made for the value of
malloc() is THAT IT IS SUITABLE FOR USE *AFTER CASTING*.  If you don't
believe me, read the standard again.
 
Yes, this is maybe just an exercise in pedantry.  Well-written standards
should survive such exercises, though.
 
Brendan McKay.   bdm at anucsd.oz  or  bdm at anucsd.oz.au



More information about the Comp.std.c mailing list