Every program written in C that I’ve ever seen #includes <stdlib.h>, at least indirectly. You can’t really do much useful without it.
Why aren’t its functions just part of “standard C”?
Why should I have to #include <stdlib.h> before malloc()ing something?
The C language was designed, from the start, to be used both in ordinary applications (running in a ‘hosted environment’) and OS kernels (and other specialized environments, running in a ‘freestanding environment’). In the latter, ordinary C library functions like
malloc()may be unavailable.In order to allow the same compiler to be used for both hosted and freestanding environments, library functions are not hardcoded into the compiler, but rather are placed into header files loaded by the compiler – such as
stdlib.h. OS kernels and other specialized programs do not (and cannot) include these standard headers.