Article View: comp.unix.programmer
Article #3605Re: gethostname() with -pedantic -ansi flags
From: Nathan Dorfman
Date: Wed, 05 Apr 2000 00:00
Date: Wed, 05 Apr 2000 00:00
44 lines
2527 bytes
2527 bytes
Jeff Shipman wrote:
>
> Sorry if this is not the correct newsgroup to post to. I
> wasn't sure which one would be right. My problem is that
> I'm compiling my program with the -pedantic and -ansi
> flags and I get the following warning:
>
> cb.c:348: warning: implicit declaration of function `gethostname'
>
> I am including unistd.h and it compiles just fine if I
> leave out those two flags. Is it because gethostname()
> is not ANSI C? If so, I'm also using a lot of GTK code
> in there, it's not ANSI C, and the compiler doesn't
> seem to mind...is there something I'm not getting? Thanks
> in advance.
$ uname -a
SunOS saltlake 5.6 Generic_105181-13 sun4u sparc
$ man gethostbyname | grep '#include'
Reformatting page. Wait... done
#include <netdb.h>
gethostbyname() is prototyped in netdb.h, not unistd.h, on Solaris (if
I were at home I would tell you that Linux, FreeBSD, NetBSD, OpenBSD
and SunOS 4.1.4 as well...but for now all I can say is I'm 99% sure
about those). The warning gcc prints means that you are calling
a function (gethostbyname()) without a prototype first, which means the
return and argument types must be inferred (hence 'implicit decl').
Include <netdb.h> in your cb.c, and you should be good to go.
> --
> +-----------------------------------------------------+
> | Jeff "Shippy" Shipman E-Mail: shippy@cs.nmt.edu |
> | Computer Science Major ICQ: 1786493 |
> | New Mexico Institute of Mining and Technology |
> | Homepage: http://www.nmt.edu/~shippy |
> +-----------------------------------------------------+
--
Nathan Dorfman <nathan@rtfm.net> [http://www.rtfm.net]
"The light at the end of the tunnel is the headlight of an approaching
train." --/usr/games/fortune
Technical Details
Message-ID:
<38EBA5F2.9F16462E@rtfm.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38EA826B.74E7DECA@cs.nmt.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,98a1efd33b1208fc X-Google-Attributes: gid11318c,public X-Google-Thread: fc89c,98a1efd33b1208fc X-Google-Attributes: gidfc89c,public X-Google-Thread: 1014db,98a1efd33b1208fc X-Google-Attributes: gid1014db,public From: Nathan Dorfman <nathan@rtfm.net> Subject: Re: gethostname() with -pedantic -ansi flags Date: 2000/04/05 Message-ID: <38EBA5F2.9F16462E@rtfm.net> X-Deja-AN: 607238291 Content-Transfer-Encoding: 7bit References: <38EA826B.74E7DECA@cs.nmt.edu> X-Accept-Language: en,ru Content-Type: text/plain; charset=us-ascii Organization: Very Poor Mime-Version: 1.0 Newsgroups: comp.unix.programmer,comp.lang.c,gnu.gcc.help