Maybe someone should update the FAQ with some of this info. From what I read on the FAQ, I never knew that casting malloc() could be this disasterous.
Maybe someone should update the FAQ with some of this info. From what I read on the FAQ, I never knew that casting malloc() could be this disasterous.
Or maybe it could be added to the FAQ that
- You can't use malloc() without including stdlib.h (or declaring a function named malloc() yourself) in C99 (in full compliance mode anyway I believe).
- If you turn up the warning level on your C89 compiler, you are warned that the function malloc() can't be found and is assumed to return an int.
Casting malloc() is not as disastrous as you may think. Pointless to some perhaps, but it does not violate any standard, and it requires quite a few things to go wrong for you to notice anything odd.
If you forget to include header files, and you aren't compiling with a high warning level, you sort of expert weird bugs, don't you?
Yeah, well I always compile with the highest warning level and treat warnings as errors. Unfortunately not too many people that I see do the same.