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


Groups > comp.std.c > #1807

Re: C11 6.3.2.3p7 Referenced Type

From Shao Miller <sha0.miller@gmail.com>
Newsgroups comp.std.c
Subject Re: C11 6.3.2.3p7 Referenced Type
Date 2013-01-04 12:25 -0500
Organization A noiseless patient Spider
Message-ID <kc73b1$26o$1@dont-email.me> (permalink)
References <kc5v4n$ing$1@dont-email.me> <ln8v8953rm.fsf@nuthaus.mib.org>

Show all headers | View raw


On 1/4/2013 11:09, Keith Thompson wrote:
> Shao Miller <sha0.miller@gmail.com> writes:
>> I noticed a change between N1256 and N1570:
>>
>>     "A pointer to an object type may be converted to a pointer to a
>> different object type. If the resulting pointer is not correctly
>> aligned68) for the referenced type, the behavior is undefined.
>> Otherwise, when converted back again, the result shall compare equal to
>> the original pointer. When a pointer to an object is converted to a
>> pointer to a character type, the result points to the lowest addressed
>> byte of the object. Successive increments of the result, up to the size
>> of the object, yield pointers to the remaining bytes of the object."
>>
>> "Referenced type"?  Is this:
>>     1. The original type of the value to undergo conversion?
>>     2. The target type of the converted value?
>>     3. The original type of the pointee that is pointed-to by the value
>> to undergo conversion?
>>     4. The pointed-to type that is the type whence the target type is
>> derived?
>>
>> The C99 wording:
>>
>>     "A pointer to an object or incomplete type may be converted to a
>> pointer to a different object or incomplete type. If the resulting
>> pointer is not correctly aligned57) for the pointed-to type, the
>> behavior is undefined. Otherwise, when converted back again, the result
>> shall compare equal to the original pointer. When a pointer to an object
>> is converted to a pointer to a character type, the result points to the
>> lowest addressed byte of the object. Successive increments of the
>> result, up to the size of the object, yield pointers to the remaining
>> bytes of the object."
>>
>> Has this already been discussed, before?  Has this been adjusted in the
>> actual Standards?
>
> I don't think this is a significant change.  Diffing the two versions of
> the paragraph, the changes are:
>
> - "object or incomplete type" --> "object type" (due to C11's change in
>    the definition of "object type" to include incomplete types;
>
> - "pointed-to type" to "referenced type"
>
> (and a change in the footnote number).
>
> Probably the committee, or perhaps just the editor, thought that
> "referenced type" was a better wording than "pointed-to type".
>
> I believe it simply refers to the type to which the pointer resulting
> from the conversion points, your option #4.  I don't see a mystery
> here; the wording, and its meaning, seem fairly straightforward.
>

Thank you, Keith.  Someone else who I respect really didn't interpret 
C99's version the same way (they held #2), then found the change in C11 
as further evidence to support that other interpretation.  Something 
along the lines of "C99 could have led to #4 due to ambiguity, but C11 
removed the ambiguity, so it's been recognized as needing fixing and 
been fixed so it doesn't lead to #4."  D'oh.

> The alignment of the object pointed to by the pointer *before* the
> conversion (option #3) isn't relevant; if that pointed-to object
> isn't correctly aligned, the construction of that pointer value
> itself would have had undefined behavior, before the conversion in
> question is evaluated.
>

That makes sense.  I find #3 a bit difficult to grok, actually.

   A a;
   (B *) &a;

I guess it asks "does the alignment requirement of a 'B' satisfy any 
'A'," where a 'B' could have a weaker alignment than an 'A', so could be 
false.  The explicit mention of character pointers and the earlier 
paragraph for 'void *' could potentially be construed to support that 
interpretation. *boggle*

Anyway, thanks again.

>> I wouldn't've guessed that a conversion resulting in an rvalue would
>> have any alignment concerns for the rvalue itself, so I'd cross out #1
>> and #2.  The C99 "pointed-to" following closely after "resulting
>> pointer" makes me think #4, but now it's gone from C11, so I'm more
>> concerned about which is right.
>

- Shao Miller

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


Thread

C11 6.3.2.3p7 Referenced Type Shao Miller <sha0.miller@gmail.com> - 2013-01-04 02:08 -0500
  Re: C11 6.3.2.3p7 Referenced Type Keith Thompson <kst-u@mib.org> - 2013-01-04 08:09 -0800
    Re: C11 6.3.2.3p7 Referenced Type Shao Miller <sha0.miller@gmail.com> - 2013-01-04 12:25 -0500
    Re: C11 6.3.2.3p7 Referenced Type lawrence.jones@siemens.com - 2013-01-04 13:47 -0500
      Re: C11 6.3.2.3p7 Referenced Type Shao Miller <sha0.miller@gmail.com> - 2013-01-04 14:56 -0500
        Re: C11 6.3.2.3p7 Referenced Type lawrence.jones@siemens.com - 2013-01-04 17:10 -0500
          Re: C11 6.3.2.3p7 Referenced Type Shao Miller <sha0.miller@gmail.com> - 2013-01-04 20:34 -0500
  Re: C11 6.3.2.3p7 Referenced Type Wojtek Lerch <wojtek_l@yahoo.ca> - 2013-01-04 23:45 -0500
    Re: C11 6.3.2.3p7 Referenced Type Shao Miller <sha0.miller@gmail.com> - 2013-01-05 02:07 -0500
      Re: C11 6.3.2.3p7 Referenced Type Shao Miller <sha0.miller@gmail.com> - 2013-01-05 02:16 -0500
    Re: C11 6.3.2.3p7 Referenced Type Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-06 17:25 -0800
      Re: C11 6.3.2.3p7 Referenced Type Wojtek Lerch <wojtek_l@yahoo.ca> - 2013-01-06 22:13 -0500
        Re: C11 6.3.2.3p7 Referenced Type Shao Miller <sha0.miller@gmail.com> - 2013-01-06 23:30 -0500
          Re: C11 6.3.2.3p7 Referenced Type Wojtek Lerch <wojtek_l@yahoo.ca> - 2013-01-07 00:07 -0500
            Re: C11 6.3.2.3p7 Referenced Type Shao Miller <sha0.miller@gmail.com> - 2013-01-07 01:29 -0500
              Re: C11 6.3.2.3p7 Referenced Type Shao Miller <sha0.miller@gmail.com> - 2013-01-07 02:18 -0500
              Re: C11 6.3.2.3p7 Referenced Type Wojtek Lerch <wojtek_l@yahoo.ca> - 2013-01-10 17:45 -0500
          Re: C11 6.3.2.3p7 Referenced Type Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-06 22:30 -0800
            Re: C11 6.3.2.3p7 Referenced Type Shao Miller <sha0.miller@gmail.com> - 2013-01-07 01:58 -0500
              Re: C11 6.3.2.3p7 Referenced Type Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-06 23:16 -0800
        Re: C11 6.3.2.3p7 Referenced Type Tim Rentsch <txr@alumni.caltech.edu> - 2013-01-06 22:02 -0800

csiph-web