Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #61963

Re: C struct compatibility when they have the same initial members

From pa@see.signature.invalid (Pierre Asselin)
Newsgroups comp.lang.c
Subject Re: C struct compatibility when they have the same initial members
Date 2015-05-14 01:33 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <mj0u18$t0k$1@reader1.panix.com> (permalink)
References <miv94g$qme$1@dont-email.me>

Show all headers | View raw


James Harris <james.harris.1@gmail.com> wrote:
> [ ... ]
> 2. Define a struct which has just the pointers and embed that at the 
> start of each of the other types as in

>   struct common {
>     struct common *next;
>     struct common *prev;
>   );

>   struct specific1 {
>     struct common c;
>     <rest of this node type>
>   };

> Again, I don't think this will work without casts.

I think it does work without a cast, but you have to name the
intermediate field, e.g. ptr->c.next, ptr->c.prev instead of just
ptr->next, ptr->prev.

-- 
pa at panix dot com

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

C struct compatibility when they have the same initial members "James Harris" <james.harris.1@gmail.com> - 2015-05-13 11:31 +0100
  Re: C struct compatibility when they have the same initial members Johann Klammer <klammerj@NOSPAM.a1.net> - 2015-05-13 17:17 +0200
  Re: C struct compatibility when they have the same initial members James Kuyper <jameskuyper@verizon.net> - 2015-05-13 12:25 -0400
    Re: C struct compatibility when they have the same initial members Ian Collins <ian-news@hotmail.com> - 2015-05-14 14:33 +1200
    Re: C struct compatibility when they have the same initial members "James Harris" <james.harris.1@gmail.com> - 2015-05-14 08:04 +0100
      Re: C struct compatibility when they have the same initial members James Kuyper <jameskuyper@verizon.net> - 2015-05-15 00:19 -0400
        Re: C struct compatibility when they have the same initial members "James Harris" <james.harris.1@gmail.com> - 2015-05-15 21:32 +0100
          Re: C struct compatibility when they have the same initial members James Kuyper <jameskuyper@verizon.net> - 2015-05-15 17:11 -0400
            Re: C struct compatibility when they have the same initial members Keith Thompson <kst-u@mib.org> - 2015-05-15 15:27 -0700
  Re: C struct compatibility when they have the same initial members Barry Schwarz <schwarzb@dqel.com> - 2015-05-13 11:22 -0700
  Re: C struct compatibility when they have the same initial members pa@see.signature.invalid (Pierre Asselin) - 2015-05-14 01:33 +0000
    Re: C struct compatibility when they have the same initial members "James Harris" <james.harris.1@gmail.com> - 2015-05-14 08:15 +0100
      Re: C struct compatibility when they have the same initial members Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-14 11:22 +0100
        Re: C struct compatibility when they have the same initial members Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-14 11:27 +0100

csiph-web