(void *) & casting the pointer returned by malloc 
Author Message
 (void *) & casting the pointer returned by malloc


> | 1) Your program will *also* have problems if you define NULL as
> | "(void *)0", if "(char *)0" and "(void *)0" don't have the same
> | representation.
> Pardon me???!  (void *) is a GENERIC pointer, is it not?  It should, in
> theory, be a type pun in all situations

(void *) is NOT a generic pointer type.  There is no such beast in C,
and I for one hope nobody introduces one.  And even if there were a
generic pointer type, one should NOT assume that it is a type pun for
all non-generic pointer types.

> (if casting the result of a rational
> malloc() (defined as returning (void *)) changes the representation of the
> pointer returned, we've got trouble, no?).

Quite the reverse, on some machines.  For example, on word-addressed
machines malloc must return a pointer with the finest possible
granularity.  Yet the pointer format for most types will have coarser
resolution.  Thus, if the cast of the return value of malloc does NOT
change the representation, then there's trouble in River City, and HOW.

"They pelted me with rocks and garbage."
                                --- David Letterman
Wayne Throop      <the-known-world>!mcnc!rti!dg_rtp!throopw

Sat, 17 Oct 1992 15:59:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Q: casting to a pointer to a function returning void

2. casting of struct element void pointer casting

3. Casting function pointer to void pointer

4. casting void pointer to be a pointer to a function

5. casting void pointer to be a pointer to a function

6. type casting malloc() to void *

7. Why cast a void return?

8. casting return value from malloc

9. Why cast malloc's return?

10. Casting pinning pointer to void *

11. Casting from a void pointer

12. Casting void pointers


Powered by phpBB® Forum Software