What does this mean ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roka

    #1

    What does this mean ?

    Hi all
    How to explain the *s below.

    char **addrs;
    ...
    printf("%s\n",i net_ntoa(*(stru ct in_addr *)*addrs));


    The define of inet_ntoa() is : char *inet_ntoa(stru ct in_addr in);

    Thanks.

  • Vladimir S. Oka

    #2
    Re: What does this mean ?

    Roka wrote:
    [color=blue]
    > Hi all
    > How to explain the *s below.
    >
    > char **addrs;
    > ...
    > printf("%s\n",i net_ntoa(*(stru ct in_addr *)*addrs));
    >
    >
    > The define of inet_ntoa() is : char *inet_ntoa(stru ct in_addr in);[/color]

    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`.

    Quite abominable, IMHO...

    --
    BR, Vladimir

    Democracy is the theory that the common people know what they want, and
    deserve to get it good and hard.
    -- H.L. Mencken, "Little Book in C major", 1916

    Comment

    • Dave Thompson

      #3
      Re: What does this mean ?

      On Mon, 6 Mar 2006 07:03:46 +0000 (UTC), "Vladimir S. Oka"
      <novine@btopenw orld.com> wrote:
      [color=blue]
      > Roka wrote:
      >[color=green]
      > > Hi all
      > > How to explain the *s below.
      > >
      > > char **addrs;
      > > ...
      > > printf("%s\n",i net_ntoa(*(stru ct in_addr *)*addrs));
      > >
      > >
      > > The define of inet_ntoa() is : char *inet_ntoa(stru ct in_addr in);[/color]
      >
      > 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`.
      >[/color]
      Right.
      [color=blue]
      > Quite abominable, IMHO...[/color]

      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.ne t

      Comment

      Working...