Thread View: comp.unix.programmer
3 messages
3 total messages
Started by Jeff Shipman
Tue, 04 Apr 2000 00:00
gethostname() with -pedantic -ansi flags
Author: Jeff Shipman
Date: Tue, 04 Apr 2000 00:00
Date: Tue, 04 Apr 2000 00:00
20 lines
1794 bytes
1794 bytes
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. -- +-----------------------------------------------------+ | 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 | +-----------------------------------------------------+
Re: gethostname() with -pedantic -ansi flags
Author: Kaz Kylheku
Date: Wed, 05 Apr 2000 00:00
Date: Wed, 05 Apr 2000 00:00
25 lines
2030 bytes
2030 bytes
On Tue, 04 Apr 2000 18:01:47 -0600, Jeff Shipman <shippy@cs.nmt.edu> 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? Not quite. It's true that this function is not ANSI C, but then again, neither is the <unistd.h> header. What is happening is that you are getting only the minimal set of identifiers out of this POSIX header; you need to add a feature selection macro something like _XOPEN_SOURCE to enable addtional things that are not in POSIX. In other words, in additon to supressing extensions in ANSI C headers and ensuring that the compiler accepts all ANSI C programs, the -ansi option also suppresses extensions in other headers, allowing you to use feature selection macros to enable specific interface standards. -- #exclude <windows.h>
Re: gethostname() with -pedantic -ansi flags
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads