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


Groups > comp.lang.c > #42377

Re: Padding involved

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Padding involved
Date 2014-03-30 19:35 -0700
Organization None to speak of
Message-ID <ln61mvhz7l.fsf@nuthaus.mib.org> (permalink)
References (13 earlier) <lh57rc$ra9$1@dont-email.me> <lnlhvtjv2n.fsf@nuthaus.mib.org> <lh6g0g$oc6$1@dont-email.me> <lnd2h4k8kb.fsf@nuthaus.mib.org> <kfn4n2fik7q.fsf@x-alumni2.alumni.caltech.edu>

Show all headers | View raw


Tim Rentsch <txr@alumni.caltech.edu> writes:
> Keith Thompson <kst-u@mib.org> writes:
>
>> James Kuyper <jameskuyper@verizon.net> writes:
>>> On 03/29/2014 03:57 AM, Keith Thompson wrote:
>>>> James Kuyper <jameskuyper@verizon.net> writes:
>>> ...
>>>>> Actually, that's precisely what double[2] is; and
>>>>> _Alignof(double[2]) probably would be 16 on such a platform.
>>>> 
>>>> N1570 6.5.3.4p3:
>>>> 
>>>>     The _Alignof operator yields the alignment requirement of its
>>>>     operand type. The operand is not evaluated and the result is
>>>>     an integer constant. When applied to an array type, the result
>>>>     is the alignment requirement of the element type.
>>>
>>> Ah - that's new, I think - I haven't had time to fully digest the
>>> changes made in C2011. In principle the same requirement could have
>>> been worded in earlier versions of the standard in terms of the
>>> alignment of the type without mentioning _Alignof(), but I don't
>>> think that it was.  Am I correct?
>>
>> Search for every occurrence of "alignment" in N1256, I see no
>> explicit statement about the alignment of array types (which is a
>> bit surprising).
>>
>> But I think the *required* alignment for an array type was already
>> the same as the required alignment for the element type.
>>
>> For example, I *think* this program, which treats "slices" of a
>> double[3] array as double[2] arrays, is strictly conforming in
>> both C99 and C11.  If double[2] could have a stricter alignment
>> requirement than double, its behavior would be undefined under any
>> implementation that imposes such an alignment.
>>
>> #include <stdio.h>
>>
>> typedef double pair[2];
>>
>> static void print(pair *p) {
>>     printf("%g %g\n", (*p)[0], (*p)[1]);
>> }
>>
>> int main(void) {
>>     double arr[3] = { 10.0, 20.0, 30.0 };
>>     pair *p0 = (pair*)&arr[0];
>>     pair *p1 = (pair*)&arr[1];
>>     print(p0);
>>     print(p1);
>> }
>
> If you mean the example program as part of an argument, it's
> a circular argument.  The program is strictly conforming if
> and only if the alignment of double[2] must be the same as
> the alignment of double.  Saying the given program is strictly
> conforming is just a sneaky way of begging the question.

It wasn't *quite* meant as an argument, more as a way to restate
the question in a perhaps clearer manner.

I *think* that C99 permits the kinds of access in this program (and
I'd be very surprised to see an implementation where it doesn't work)
but I haven't found wording that proves or disproves it.

[...]

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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