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


Groups > comp.std.c > #1374

Re: Structure Packing.

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.stack.nl!aioe.org!.POSTED!not-for-mail
From Walter Banks <walter@bytecraft.com>
Newsgroups comp.std.c
Subject Re: Structure Packing.
Date Tue, 12 Jun 2012 17:17:50 -0400
Organization Aioe.org NNTP Server
Lines 35
Message-ID <4FD7B1FE.7BE5D0E@bytecraft.com> (permalink)
References <12b3df42-f6a0-4411-a5e5-136900f8255b@googlegroups.com> <jqovin$9sr$1@dont-email.me> <4FD6ABFA.72F52C75@bytecraft.com> <jr7fpp$eti$1@dont-email.me> <jr7qcu$p1u$1@dont-email.me> <4FD79758.38D5CBF0@bytecraft.com> <jr892f$um1$1@dont-email.me>
NNTP-Posting-Host uMDnRznCaHm25BLlk25agA.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
X-Mailer Mozilla 4.79 [en]C-CCK-MCD NSCPCD479 (Windows NT 5.0; U)
X-Accept-Language en
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.std.c:1374

Show key headers only | View raw



Eric Sosman wrote:

>
>
>      That would make me uncomfortable, too.  Remember, it's always
> allowed to convert a pointer to a struct to a pointer to its first
> element and vice versa, and if your compiler rearranges the element
> order this could break rather badly.  Think of all those linked
> lists where the "next" pointer is assumed to be the first thing in
> the struct (so "generic" functions can find it), and think of the
> havoc that could ensue if the compiler silently shuffled a "double"
> into first place in the name of storage efficiency ...

The first element is never going to be a problem in this case.
One of the very few really good things is that I will never need
to pad the first element. It can for example be either a char
or int and in every case be referenced by it actual first
element address.

>      One thing you might consider would be to have your compiler
> emit a warning message for inefficiently-arranged structs.  (The
> compiler is always permitted to whine, even about perfectly legal
> code.)  This would draw people's attention to wasteful constructs
> without breaking C conformance.

I am coming to that conclusion. Even better it is reasonably easy for
the compiler to define a cleaner declaration and make the whining helpful.

Thanks

w..

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


Thread

Structure Packing. John Kearney <dethrophes@googlemail.com> - 2012-06-06 17:27 -0700
  Re: Structure Packing. James Kuyper <jameskuyper@verizon.net> - 2012-06-06 21:19 -0400
    Re: Structure Packing. Walter Banks <walter@bytecraft.com> - 2012-06-11 22:39 -0400
      Re: Structure Packing. Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-12 09:21 -0400
        Re: Structure Packing. Walter Banks <walter@bytecraft.com> - 2012-06-12 11:51 -0400
          Re: Structure Packing. Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2012-06-12 18:37 +0200
            Re: Structure Packing. Walter Banks <walter@bytecraft.com> - 2012-06-12 15:06 -0400
              Re: Structure Packing. Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-12 16:22 -0400
                Re: Structure Packing. Walter Banks <walter@bytecraft.com> - 2012-06-12 17:44 -0400
                Re: Structure Packing. Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2012-06-13 15:53 +0200
                Re: Structure Packing. Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-06-18 12:37 +0300
        Re: Structure Packing. Martin Shobe <martin.shobe@yahoo.com> - 2012-06-12 16:22 +0000
          Re: Structure Packing. Walter Banks <walter@bytecraft.com> - 2012-06-12 15:24 -0400
            Re: Structure Packing. Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-12 16:33 -0400
              Re: Structure Packing. Walter Banks <walter@bytecraft.com> - 2012-06-12 17:17 -0400
  Re: Structure Packing. Keith Thompson <kst-u@mib.org> - 2012-06-06 18:35 -0700
    Re: Structure Packing. John Kearney <dethrophes@googlemail.com> - 2012-06-06 21:58 -0700
      Re: Structure Packing. Keith Thompson <kst-u@mib.org> - 2012-06-06 23:54 -0700
        Re: Structure Packing. John Kearney <dethrophes@googlemail.com> - 2012-06-07 07:47 -0700
          Re: Structure Packing. James Kuyper <jameskuyper@verizon.net> - 2012-06-07 12:39 -0400
    Re: Structure Packing. jacob navia <jacob@spamsink.net> - 2012-06-07 11:14 +0200
      Re: Structure Packing. Keith Thompson <kst-u@mib.org> - 2012-06-07 09:46 -0700
        Re: Structure Packing. John Kearney <dethrophes@googlemail.com> - 2012-06-07 11:57 -0700

csiph-web