When do you #include <stdlib.h>?

Doug Gwyn gwyn at brl-smoke.ARPA
Wed Mar 23 04:53:19 AEST 1988


In article <4991 at sigi.Colorado.EDU> murillo at boulder.Colorado.EDU (Rodrigo Murillo) writes:
>     printf("foo: %dl",atol(argv[1]));
>The prototype for atol() resides in stdlib.h.  The above code compiles
>without an #include <stdlib.h>, but the expresion yields rubbish.

Naturally, since the compiler assumes that the return type of a function
is int if it is invoked with no declaration in scope.  Since the correct
return type for atol() is long, the default assumption is incorrect and
the wrong format of data is passed as an argument to printf().



More information about the Comp.lang.c mailing list