Re: gcc oddities : why would this compile?
On Fri, 4 Jan 2002 21:41:13 -0500, dman <dsh8290@rit.edu> wrote:
>
> 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).
By the looks of it, I would contend you have found a bug. I think my
contention is supported by the fact the using -Wall causes the compilation
to fail at the linker. So why would -Wall cause it to fail at the
linker when not using it doesn't? Using -pedantic-errors, does catch
and stop the compilation before the linker is called. So, I'm not
hundred percent sure it'd be a bug. GCC does try to support K&R, so
will relax checking if it thinks it is supposed to "int main()" ??
I find GCC is often too lax and wish it'd generate more compilation
errors out of the box. I suppose, I could change the defaults somewhere.
> 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.
CONFORMING TO
SVr4, SVID, POSIX, X/OPEN. There is no uname call in BSD 4.3.
The domainname member (the NIS or YP domain name) is a GNU exten
sion.
If you want all the GNU extensions, use -D_GNU_SOURCE or #define it.
--
Eric G. Miller <egm2@jps.net>
Reply to: