Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Feb 1999 16:57:25 -0500 (EST)
From:      Thomas David Rivers <rivers@dignus.com>
To:        Hackers@FreeBSD.ORG, Matthew.Alton@anheuser-busch.com
Subject:   Re: C headers
Message-ID:  <199902052157.QAA01582@lakes.dignus.com>
In-Reply-To: <31B3F0BF1C40D11192A700805FD48BF90177670F@STLABCEXG011>

next in thread | previous in thread | raw e-mail | index | archive | help
> 
> Why does printf() non need #include <stdio.h> 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 <stdio.h>.  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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199902052157.QAA01582>