Why would I want to typecast the malloc function? The reason I ask this is that I never have but have seen numerous tutorials with examples of them doing this including cprogrammin.com.
Why would I want to typecast the malloc function? The reason I ask this is that I never have but have seen numerous tutorials with examples of them doing this including cprogrammin.com.
You don't typecast the malloc function. The reason you see it cast all the time is because back in the day, C didn't use void pointers and malloc was defined with a char pointer. So if you tried to assign the return of malloc to anything but a character, you'd get a problem, so you cast it. Since then, it's used a void pointer and is not required to be cast.
Sent from my iPadŽ
Thx Slymaelstrom as you have cleared this up for me. Didn't know the old function declaration was different.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*