R
Robert Stankowic
Reading through the recent discussions about casting/not casting the return
value of *alloc() I stumbled over a probably obvious thought:
There is a difference between a generic void * and the void * returned from
*alloc, because a generic void * has no alignment requirements, while the
void * returned from *alloc() is properly aligned for any type of object.
This eliminates the danger of getting a misaligned <TYPE> *, which IMHO
makes the assignment
<TYPE> *p = malloc(<some_size> * sizeof *P);
perfectly safe in all cases I can imagine.
[OT] I even wonder, why this is not allowed in C++. [/OT]
Any comments?
regards
Robert
value of *alloc() I stumbled over a probably obvious thought:
There is a difference between a generic void * and the void * returned from
*alloc, because a generic void * has no alignment requirements, while the
void * returned from *alloc() is properly aligned for any type of object.
This eliminates the danger of getting a misaligned <TYPE> *, which IMHO
makes the assignment
<TYPE> *p = malloc(<some_size> * sizeof *P);
perfectly safe in all cases I can imagine.
[OT] I even wonder, why this is not allowed in C++. [/OT]
Any comments?
regards
Robert