Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!asuvax!enuxha!hurwitz From: hurwitz@enuxha.eas.asu.edu (Roger A. Hurwitz) Newsgroups: comp.lang.c Subject: casting void pointers Keywords: void, pointer, malloc(), cast Message-ID: <3121@enuxha.eas.asu.edu> Date: 20 Apr 91 17:59:45 GMT Organization: Arizona State University, Tempe, AZ Lines: 21 Appendix A, section 6.8, of K&R 2d, states in part, "Unlike the pointer-to-pointer conversions discussed in [section] A6.6, which generally require an explicit cast, pointers may be assigned to and from pointers of type *void, and may be compared with them." Does this mean that the explicit cast that one always sees with malloc() is unnecessary since malloc() returns a void pointer? For example, why not: fooptr = malloc(sizeof(struct foo)); instead of: fooptr = (struct foo *) malloc(sizeof(struct foo)); Even K&R 2d states that an explicit cast should be used with malloc(), in another part of the book (p. 142), but I am having trouble reconciling that with the above language.