Common malloc/free practice violates ANSI standard ?

Mike Haertel mike at thor.acc.stolaf.edu
Mon Oct 16 03:42:16 AEST 1989


In article <1989Oct14.043811.669 at anucsd.oz> bdm at anucsd.oz (Brendan McKay) writes:
>* assigning a void* to an OBJ* involves rounding up to an even address

The standard doesn't say anything about "rounding" pointers.
Assigning a misaligned void* to an OBJ* might well cause a trap when
the OBJ* is dereferenced.  Or even when the void* is just assigned to it!

>* malloc allocates sufficient space so that it will cover an object of
>  type OBJ even when the void* value returned is rounded up to even.
>  (Thus, sometimes it actually allocates one more cell than it is asked for.)

No!  The pointer returned by malloc() always has the most pessimistic
necessary alignment.
-- 
Mike Haertel <mike at stolaf.edu>
``There's nothing remarkable about it.  All one has to do is hit the right
  keys at the right time and the instrument plays itself.'' -- J. S. Bach



More information about the Comp.lang.c mailing list