From owner-freebsd-hackers Fri Feb 5 13:55:42 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA08668 for freebsd-hackers-outgoing; Fri, 5 Feb 1999 13:55:42 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from smtp1.vnet.net (smtp1.vnet.net [166.82.1.31]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA08659 for ; Fri, 5 Feb 1999 13:55:35 -0800 (PST) (envelope-from rivers@dignus.com) Received: from dignus.com (ponds.vnet.net [166.82.177.48]) by smtp1.vnet.net (8.9.1a/8.9.1) with ESMTP id QAA03029; Fri, 5 Feb 1999 16:56:11 -0500 (EST) Received: from lakes.dignus.com (lakes.dignus.com [10.0.0.3]) by dignus.com (8.9.1/8.8.5) with ESMTP id RAA00881; Fri, 5 Feb 1999 17:38:46 -0500 (EST) Received: (from rivers@localhost) by lakes.dignus.com (8.9.1/8.6.9) id QAA01582; Fri, 5 Feb 1999 16:57:25 -0500 (EST) Date: Fri, 5 Feb 1999 16:57:25 -0500 (EST) From: Thomas David Rivers Message-Id: <199902052157.QAA01582@lakes.dignus.com> To: Hackers@FreeBSD.ORG, Matthew.Alton@anheuser-busch.com Subject: Re: C headers In-Reply-To: <31B3F0BF1C40D11192A700805FD48BF90177670F@STLABCEXG011> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > Why does printf() non need #include like the man page says? It works because - without a declaration, printf() is assumed to be a function that can accept any number of arguments (promoted via the K&R promotion rules), that returns an int. So - in this case, the compiler simply emits code to call the printf() function. And, since you didn't use the (compiler assumed) return value - didn't bother to look at it. Using the Systems/C compiler (a C compiler for 370 mainframes) you would get a nice warning message that printf() isn't declared. (try it your code on http://www.dignus.com) - Dave Rivers - > > -------------------------------------- foo.c > int > mean(int a, int b) > { > return (a + b) / 2; > } > > int > main() > { > int i = 0, j = 0, answer = 0; > > i = 7; > j = 9; > > answer = mean(i, j); > printf("The mean of %d and %d is %d\n", i, j, answer); > > return 0; > } > ---------------------------------------------- > > builds without a #include . A student asked me why and I can't explain > this inconsistency. > > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message