Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!necntc!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: When do you #include ? Message-ID: <3122@haddock.ISC.COM> Date: 22 Mar 88 23:38:34 GMT References: <4991@sigi.Colorado.EDU> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Distribution: na Organization: Interactive Systems, Boston Lines: 21 In article <4991@sigi.Colorado.EDU> murillo@boulder.Colorado.EDU (Rodrigo Murillo) writes: >I realized today that you can call functions that are in stdlib.h >without actually including them in your file. But on the otherhand >you can include them. Is there a hard fast rule? Let me give an >example: > printf("foo: %dl",atol(argv[1])); The rule is that you are allowed to omit the #include, provided that you supply a compatible declaration yourself. Thus, you could have said "extern long atol(char *);" or "extern long atol();" and your program would have been correct. Since nothing explicit was encountered, the implied declaration was "extern int atol();" which was incorrect. >Why doesn't the compiler barf when it encounters atol() when the stdlib.h is >NOT included? Absence of a prototype has to be permitted for compatibility with pre-ANSI C. The better compilers will have an option to generate a warning, though. Btw, that should be "%ld", not "%dl". Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint