I'm aware that in C it's best practice to never cast the return value of malloc()
. I've read that the compiler assumes that malloc()
returns an int if you don't include stdlib.h
. Of course it would produce an error if you tried to implicitly assign an int to something that's not an int, but that error could be covered up by an explicit cast -- hence the danger of explicitly casting malloc()
.
For any function I've created, if the function doesn't exist then the compiler will tell me so. Why does the compiler assume that malloc()
returns int even if you haven't included stdlib.h
? Shouldn't malloc()
just remain undefined until you include stdlib.h
?