On Tue, May 24, 2005 at 05:03:27PM +0200, Andreas Schwab wrote:
> Paul Koning <[EMAIL PROTECTED]> writes:
> > I hope that doesn't require (void *) casts for pointer arguments
> > passed to the likes of memcpy...
> 
> Only the (void*) -> (any*) direction requires a cast in C++, the other
> direction is still converted implicitly.

In my view, the decision by the C standards committees to allow the
omission of the cast in the reverse direction was a bad mistake (and I
wrote my first C program in 1981, if I recall correctly).
While, in

    int * int_p = malloc(num_integers * sizeof(int));

the operation is safe, this is only because the void* returned by malloc
is different from the void* obtained by, say,

    double d_var;
    void * p;
    ...
    p = &d_var;

since one is safe to assign to an int* and the other is not.  We really
have two different types here; one represents the top of a lattice and
the other represents the bottom.  It would have been nice if there
were a type "aligned_pointer_t" to represent the kind of object returned
by malloc.

For this reason, I always cast the result of malloc to the proper type;
it just feels wrong otherwise.

Reply via email to