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


Groups > comp.std.c > #1806

Re: C11 6.3.2.3p7 Referenced Type

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.std.c
Subject Re: C11 6.3.2.3p7 Referenced Type
Date 2013-01-04 08:09 -0800
Organization None to speak of
Message-ID <ln8v8953rm.fsf@nuthaus.mib.org> (permalink)
References <kc5v4n$ing$1@dont-email.me>

Show all headers | View raw


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.

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.

> 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.

-- 
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.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