Earlier I asked one question that is if the return of malloc is cast then the error which would be flagged is hidden
and I got the answer that is: In (older dialects of) C, you can call a function which hasn't been declared; that implicitly declares a function with a return type of int
. So, if you were to call malloc()
without including the header, you'd get code that erroneously assumed that it returned int
. Without a cast, you'd get a compiler error when you tried to assign it to a pointer. With a cast, the code would compile, potentially giving obscure runtime errors and lengthy debugging sessions.
I understand that without inclusion of <stdlib.h>
header file compiler implicitly declares a function with a return type of int
.
But I confused in that according to malloc()
's function definition that is defined by creator, it will returns void *
whenever we used it, but without <stdlib.h>
it returns int
. So how does its definition change, is compiler implicitly changing void *
to int *
type, or there is some other reason?
I know that I couldn't explain my question properly but if anybody understand, please explain me about that.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…