[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: gcc oddities : why would this compile?



On Fri, Jan 04, 2002 at 21:41:13 -0500, dman wrote:
> Why does this compile without any errors?  (no options were given to
> gcc)

Because you didn't request relevant warnings like -Wimplicit (included in
-Wall), which would have given you
	foo.c: In function `main':
	foo.c:4: warning: implicit declaration of function `puts'
	foo.c:4: warning: implicit declaration of function `uname'

> Why don't I need to include stdio.h or sys/utsname.h?

Because C does not require you to declare functions before use. Including a
header file tells the compiler about functions. Seeing to it that
implementations of functions you call are really available is not the
compiler's job, but the linker's. And because gcc will call the linker
'-lc', the implementations of puts() and uname() will be found.

> The odd part is that the 'domainname' member isn't present because
> _GNU_SOURCE isn't defined on my system.

That's because GNU libc tries to be as compatible as is reasonably possible
with source code that assumes one of Un*x's many standards (POSIX, SysV,
BSD, X/Open, C89, C99 etc.). See "info libc introduction using feature". If
you want GNU extensions, compile -D_GNU_SOURCE .

HTH,
Ray
-- 
Gartner is what you get when you pipe statistics through consultants.
	- jtv



Reply to: