On Mon, 6 Mar 2006 07:03:46 +0000 (UTC), "Vladimir S. Oka"
<no****@btopenworld.com> wrote:
Roka wrote:
Hi all
How to explain the *s below.
char **addrs;
...
printf("%s\n",inet_ntoa(*(struct in_addr *)*addrs));
The define of inet_ntoa() is : char *inet_ntoa(struct in_addr in);
I guess what was tried was:
`addrs` is a pointer to a pointer to `char`
`*addrs` gets you the pointer to `char`
`(struct in_addr *)*addrs` casts that to a pointer to `struct in_addr`
that is then dereferenced to be passed to `inet_ntoa()`
So, it seems that wherever the pointer `addrs` points, is supposed to
contain a series of `char`s, which are supposed to be able to be
interpreted as `struct in_addr`.
Right.
Quite abominable, IMHO...
Poor for standard C, yes. <OT> However, this is the type returned by
the (BSD-to-SUS/POSIX) gethost* functions for the list of network
addresses, since the API was intended to support a whole range of
protocol stacks, of which only 2 survive and only 1 (IP) matters.
The whole BSD API was designed to use a series of structures that are
in fact laid out to be compatible, but are not declared that way to
the C compiler to allow separate development (and extension), and thus
is one of the few places well-written (Unixoid) C _needs_ casts.
In retrospect it is not clear whether this design was really worth it,
but it's far too late to change now. </>
- David.Thompson1 at worldnet.att.net