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

gcc oddities : why would this compile?



I have both gcc 2.95.4 and gcc 3.0.2 installed.  Both of them compiled
this C program (this is the entire thing) :

-----------
int
main()
{
    puts( uname() ) ;
    return 0 ;
}
-----------

Why does this compile without any errors?  (no options were given to
gcc)  Why don't I need to include stdio.h or sys/utsname.h?  After I
looked at the docs (I just wanted to see what the function would
return) I saw that it returns an int to indicate success/failure and
takes a pointer to a struct utsname as an out-argument.  (the program
above naturally seg faults)  I get the same sort of effect with
gethostbyname() (I should include netdb.h, it takes a string argument
and returns a pointer to a struct hostent).

The other thing that strikes me as odd, is the following portion of
the struct utsname definition (in the manpage) :

    #ifdef _GNU_SOURCE
        char domainname[SYS_NMLN] ;
    #endif

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

-D

-- 

Commit to the Lord whatever you do,
and your plans will succeed.
        Proverbs 16:3



Reply to: