Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!pacbell!att-ih!ihnp4!inuxc!iuvax!pur-ee!uiucdcs!bradley!bucc2!brian From: brian@bucc2.UUCP Newsgroups: comp.lang.c Subject: Re: When do you #include ? Message-ID: <13100007@bucc2> Date: 24 Mar 88 03:54:00 GMT References: <4991@sigi.Colorado.EDU> Lines: 35 Nf-ID: #R:sigi.Colorado.EDU:4991:bucc2:13100007:000:1365 Nf-From: bucc2.UUCP!brian Mar 23 21:54:00 1988 > /* ---------- "When do you #include ?" ---------- */ > 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 prototype for atol() resides in stdlib.h. The above code compiles > without an #include , but the expresion yields rubbish. When > the stdlib.h is included, it works fine. What gives? Why doesn't the > compiler barf when it encounters atol() when the stdlib.h is NOT included? Since you didn't tell it otherwise, your compiler assumed that atol() returned an integer. It actually returned a long integer, and since your program produces garbage output I gather sizeof(int) != sizeof(long) under your implementation. If you didn't want to include , you could of done the prototype yourself: long atol(); or if you are blessed with an ANSI compiler long atol(char *str); ............................................................................... When the going gets weird, the weird turn pro. Brian Michael Wendt UUCP: {cepu,ihnp4,uiucdcs,noao}!bradley!brian Bradley University ARPA: cepu!bradley!brian@seas.ucla.edu (309) 691-5175 ICBM: 40 40' N 89 34' W