Mail Archives: djgpp/1999/07/20/07:20:40
Michael Stewart wrote:
: The code I posted used a cast to tell the compiler that the allocated
: will be used as float*. Ed didn't use a cast.
It's good practice not to cast, malloc doesn't require a cast and a cast
can sometimes mask errors.
: malloc returns void* and by using a cast it'll prevent the compiler
: complaining about converting between types. It should be quite safe to
: the memory without the cast though.
If the comiler is complaining about not casting malloc's return, this
is one of the cases where casting it will mask an error.
If my compiler moans about not casting the return of malloc it's
because I have forgotten to #include <stdlib.h>
You should only ever need to cast malloc when dynamically allocating
a mutidimensional array.
- Raw text -