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


Groups > comp.lang.c > #42588

Re: Padding involved

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: Padding involved
Date 2014-04-04 17:33 -0400
Organization Self
Message-ID <533F251B.7000404@verizon.net> (permalink)
References (16 earlier) <lh71r5$shv$1@dont-email.me> <lha8ck$dng$1@dont-email.me> <lhcm73$i1n$1@dont-email.me> <5339E3CE.4030403@verizon.net> <lhn1j5$t11$1@dont-email.me>

Show all headers | View raw


On 04/04/2014 03:36 PM, Stephen Sprunk wrote:
> On 31-Mar-14 16:53, James Kuyper wrote:
...
>> However, realize that there's a wide variety of other interesting 
>> mathematical results that can be derived from those same facts. For 
>> instance, in C2011, the requirement was added that alignment 
>> requirements had to be powers of 2, which matches what essentially
>> all known implementations of C actually do, or have ever actually
>> done. However, prior to that change, a conforming implementation
>> could have had alignment requirements for short and long that were 3
>> bytes and 5 bytes, respectively. From C99, it could be proven, using
>> the same set of facts mentioned above, that any struct or union
>> containing both a short and a long must have a alignment requirement
>> when using that implementation, which is an integer multiple of both
>> 3 and 5, and therefore must be a multiple of 15.
> 
> Could one have addressed that by stating the struct's alignment must be
> a positive integer multiple of each* member's alignment?
> 
> (* Or should that be "every"?  Neither sounds exactly correct.)

I think "every" would be correct.

> Once you require power-of-two alignments, though, it suffices to say
> that the struct's alignment must be at least as strict as all of its
> members.

Which is why I had to hark back to an earlier version of the standard to
come up with an example of something that is less obvious.

>> Should the C99 standard have explicitly said something that would
>> lead to that conclusion more directly, perhaps by expressing the
>> relationship in terms of LCM (least common multiple)? I know from
>> personal experience that very few people were aware of that fact.
>> More than a few people argued with me about this when I brought it
>> up. I think this was mainly because most of them had the "power of 2"
>> rule already engraved in their brains, long before it was officially
>> adopted as a requirement. When a and b are non-negative integer
>> powers of two, LCM(a,b) == MAX(a,b), which is what most people
>> actually used when thinking about such issues.
> 
> Good point, though the argument for LCM would be clearer if your example
> alignments weren't relatively prime, i.e. if GCF(a,b) != 1.

I suppose it would be clearer what the general rule is if a and b have
some factors in common, and each one has some factors not in common with
the other; such as 4 and 6, with an LCM of 12.

> Now, of course, LCM(a,b) == MAX(a,b) and GCF(a,b) == MIN(a,b).
> 
>> How do you decide which technically redundant facts need to be 
>> explicitly spelled out, and which ones should be left for readers to 
>> derive for themselves?
> 
> I suppose that's a judgment call, but I found it surprising that when
> searching N1570 for "alignment" and then "struct", I found absolutely
> nothing useful about how structs needed to be aligned.  That seems to
> indicate they erred on the side of not enough redundancy, but I can
> appreciate that redundancy introduces a risk of inconsistency.

In standardese, that's handled by distinguishing between normative and
non-normative text. The normative text should never say the same thing
two different ways, because of the potential problems if the two ways
turn out to be subtly in conflict with each other. However, you can put
redundant statements in non-normative text, such as footnotes, and if
they turn out to conflict with the normative text, the normative text is
right, and the non-normative text is not. The accuracy of the standard
itself isn't in danger, just that of the individual footnotes.

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


Thread

Padding involved anish singh <anish198519851985@gmail.com> - 2014-03-07 13:13 -0800
  Re: Padding involved jacob navia <jacob@spamsink.net> - 2014-03-07 22:17 +0100
  Re: Padding involved Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-07 16:26 -0500
    Re: Padding involved anish singh <anish198519851985@gmail.com> - 2014-03-07 13:49 -0800
      Re: Padding involved Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-07 18:11 -0500
        Re: Padding involved anish kumar <yesanishhere@gmail.com> - 2014-03-07 15:19 -0800
          Re: Padding involved Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2014-03-07 16:26 -0700
            Re: Padding involved anish kumar <yesanishhere@gmail.com> - 2014-03-07 15:41 -0800
              Re: Padding involved James Kuyper <jameskuyper@verizon.net> - 2014-03-07 18:50 -0500
            Re: Padding involved glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-08 00:10 +0000
              Re: Padding involved Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2014-03-08 09:27 -0700
          Re: Padding involved Keith Thompson <kst-u@mib.org> - 2014-03-07 16:24 -0800
            Re: Padding involved anish kumar <yesanishhere@gmail.com> - 2014-03-07 16:45 -0800
              Re: Padding involved Kaz Kylheku <kaz@kylheku.com> - 2014-03-08 01:03 +0000
                Re: Padding involved David Thompson <dave.thompson2@verizon.net> - 2014-03-28 06:11 -0400
                Re: Padding involved glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-28 18:45 +0000
                Re: Padding involved James Kuyper <jameskuyper@verizon.net> - 2014-03-28 15:23 -0400
                Re: Padding involved Keith Thompson <kst-u@mib.org> - 2014-03-28 12:40 -0700
                Re: Padding involved glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-28 21:19 +0000
                Re: Padding involved Stephen Sprunk <stephen@sprunk.org> - 2014-03-28 17:07 -0500
                Re: Padding involved Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-28 18:25 -0400
                Re: Padding involved Stephen Sprunk <stephen@sprunk.org> - 2014-03-28 21:15 -0500
                Re: Padding involved Keith Thompson <kst-u@mib.org> - 2014-03-29 01:03 -0700
                Re: Padding involved Tim Rentsch <txr@alumni.caltech.edu> - 2014-03-29 14:23 -0700
                Re: Padding involved glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-30 01:43 +0000
                Re: Padding involved James Kuyper <jameskuyper@verizon.net> - 2014-03-28 21:32 -0400
                Re: Padding involved Richard Damon <Richard@Damon-Family.org> - 2014-03-28 21:59 -0400
                Re: Padding involved Stephen Sprunk <stephen@sprunk.org> - 2014-03-29 00:46 -0500
                Re: Padding involved James Kuyper <jameskuyper@verizon.net> - 2014-03-29 08:51 -0400
                Re: Padding involved Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-29 08:57 -0400
                Re: Padding involved Stephen Sprunk <stephen@sprunk.org> - 2014-03-30 18:53 -0500
                Re: Padding involved Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-30 20:25 -0400
                Re: Padding involved Stephen Sprunk <stephen@sprunk.org> - 2014-03-31 11:34 -0500
                Re: Padding involved Keith Thompson <kst-u@mib.org> - 2014-03-31 11:27 -0700
                Re: Padding involved Keith Thompson <kst-u@mib.org> - 2014-03-31 11:36 -0700
                Re: Padding involved Kaz Kylheku <kaz@kylheku.com> - 2014-03-31 19:14 +0000
                Re: Padding involved Stephen Sprunk <stephen@sprunk.org> - 2014-03-31 15:43 -0500
                Re: Padding involved Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2014-04-01 03:12 +0300
                Re: Padding involved Stephen Sprunk <stephen@sprunk.org> - 2014-04-03 00:45 -0500
                Re: Padding involved Stephen Sprunk <stephen@sprunk.org> - 2014-03-29 13:02 -0500
                Re: Padding involved Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-29 14:44 -0400
                Re: Padding involved glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-29 19:49 +0000
                Re: Padding involved James Kuyper <jameskuyper@verizon.net> - 2014-03-30 19:12 -0400
                Re: Padding involved Stephen Sprunk <stephen@sprunk.org> - 2014-03-31 16:20 -0500
                Re: Padding involved James Kuyper <jameskuyper@verizon.net> - 2014-03-31 17:53 -0400
                Re: Padding involved Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2014-04-01 03:22 +0300
                Re: Padding involved Stephen Sprunk <stephen@sprunk.org> - 2014-04-04 14:36 -0500
                Re: Padding involved James Kuyper <jameskuyper@verizon.net> - 2014-04-04 17:33 -0400
                Re: Padding involved Tim Rentsch <txr@alumni.caltech.edu> - 2014-04-14 13:46 -0700
                Re: Padding involved glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-14 22:00 +0000
                Re: Padding involved Keith Thompson <kst-u@mib.org> - 2014-04-14 15:37 -0700
                Re: Padding involved Tim Rentsch <txr@alumni.caltech.edu> - 2014-04-17 09:11 -0700
                Re: Padding involved Tim Rentsch <txr@alumni.caltech.edu> - 2014-04-14 13:25 -0700
                Re: Padding involved Keith Thompson <kst-u@mib.org> - 2014-03-29 00:57 -0700
                Re: Padding involved James Kuyper <jameskuyper@verizon.net> - 2014-03-29 08:57 -0400
                Re: Padding involved Keith Thompson <kst-u@mib.org> - 2014-03-29 14:18 -0700
                Re: Padding involved Tim Rentsch <txr@alumni.caltech.edu> - 2014-03-30 12:02 -0700
                Re: Padding involved Keith Thompson <kst-u@mib.org> - 2014-03-30 19:35 -0700
                Re: Padding involved Tim Rentsch <txr@alumni.caltech.edu> - 2014-04-14 12:54 -0700
                Re: Padding involved Tim Rentsch <txr@alumni.caltech.edu> - 2014-03-29 14:44 -0700
                Re: Padding involved glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-03-29 03:50 +0000
                Re: Padding involved James Kuyper <jameskuyper@verizon.net> - 2014-03-29 09:02 -0400
                Re: Padding involved Stephen Sprunk <stephen@sprunk.org> - 2014-03-29 13:19 -0500
                Re: Padding involved James Kuyper <jameskuyper@verizon.net> - 2014-03-28 21:21 -0400
                Re: Padding involved Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-28 15:27 -0400
                Re: Padding involved Kaz Kylheku <kaz@kylheku.com> - 2014-03-28 19:54 +0000
                Re: Padding involved Stephen Sprunk <stephen@sprunk.org> - 2014-03-28 15:02 -0500
          Re: Padding involved Kaz Kylheku <kaz@kylheku.com> - 2014-03-08 00:43 +0000
          Re: Padding involved Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-03-07 20:20 -0500
    Re: Padding involved anish singh <anish198519851985@gmail.com> - 2014-03-07 13:49 -0800
  Re: Padding involved James Kuyper <jameskuyper@verizon.net> - 2014-03-07 16:46 -0500
  Re: Padding involved "BartC" <bc@freeuk.com> - 2014-03-07 21:59 +0000
    Re: Padding involved anish kumar <yesanishhere@gmail.com> - 2014-03-07 14:34 -0800
      Re: Padding involved "BartC" <bc@freeuk.com> - 2014-03-07 23:59 +0000
    Re: Padding involved Keith Thompson <kst-u@mib.org> - 2014-03-07 15:15 -0800
      Re: Padding involved "BartC" <bc@freeuk.com> - 2014-03-08 10:08 +0000
        Re: Padding involved Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-08 12:39 +0000
        Re: Padding involved Keith Thompson <kst-u@mib.org> - 2014-03-08 14:03 -0800
  Re: Padding involved Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-03-08 09:01 -0800

csiph-web