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


Groups > comp.lang.c > #159267

Re: container_of macro...

Message-ID <j4plhh-vnt1.ln1@wilbur.25thandClement.com> (permalink)
From William Ahern <william@25thandClement.com>
Subject Re: container_of macro...
Newsgroups comp.lang.c
References <s26io0$nne$1@gioia.aioe.org>
Date 2021-03-09 18:56 -0800

Show all headers | View raw


Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
> Its been a while since I used the container_of macro, however, it can 
> come in handy wrt creating linked data-structures. Here is an example I 
> coded up, just to see if I could do it from scratch, after all these years:

The biggest problem with container_of is that it's not typesafe. I never
understood why the GNU and Linux ecosystem adopted that approach instead of
the classic BSD macros:

  https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/sys/queue.h

But today even glibc and musl libc provide <sys/queue.h>. As do AIX,
Solaris, and QNX, though AIX only provides LIST and TAILQ. I'm not sure when
these environments added <sys/queue.h>, but they're there now, so I can't
complain. Perhaps Windows will finally add them, making them de facto
standard interfaces[1], though being of BSD heritage neither WG14 nor POSIX
are likely to give them serious consideration. Too practical.

[1] No accounting for all the other proprietary embedded environments,
though importing queue.h from one of the BSDs is hardly burdensome. It's
recognizing the need that's apparently burdensome, given the history of NIH
reinvention.

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


Thread

container_of macro... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-08 17:24 -0800
  Re: container_of macro... Öö Tiib <ootiib@hot.ee> - 2021-03-09 02:06 -0800
    Re: container_of macro... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-10 17:02 -0800
  Re: container_of macro... Kaz Kylheku <563-365-8930@kylheku.com> - 2021-03-09 15:59 +0000
    Re: container_of macro... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-03-09 17:35 +0000
      Re: container_of macro... Kaz Kylheku <563-365-8930@kylheku.com> - 2021-03-09 17:51 +0000
        Re: container_of macro... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-10 17:13 -0800
    Re: container_of macro... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-10 17:05 -0800
  Re: container_of macro... William Ahern <william@25thandClement.com> - 2021-03-09 18:56 -0800
    Re: container_of macro... Kaz Kylheku <563-365-8930@kylheku.com> - 2021-03-10 03:47 +0000
      Re: container_of macro... William Ahern <william@25thandClement.com> - 2021-03-12 17:01 -0800
        Re: container_of macro... Jim <jim.cromie@gmail.com> - 2021-03-16 22:14 -0700
    Re: container_of macro... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-10 17:07 -0800

csiph-web