<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 701</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="701"></A><H4>701.
  
When is the array-to-pointer conversion applied?
</H4>
<B>Section: </B>9.3.4.5&#160; [<A href="https://wg21.link/dcl.array">dcl.array</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD2
 &#160;&#160;&#160;

 <B>Submitter: </B>Eelis van der Weegen
 &#160;&#160;&#160;

 <B>Date: </B>13 July, 2008<BR>


<P>[Voted into WP at March, 2010 meeting.]</P>

<P>Paragraph 7 of 9.3.4.5 [<A href="https://wg21.link/dcl.array">dcl.array</A>] says,</P>

<BLOCKQUOTE>

If <TT>E</TT> is an <I>n</I>-dimensional array of rank <I>i</I>
&#215; <I>j</I> &#215; ... &#215; <I>k</I>, then <TT>E</TT>
appearing in an expression is converted to a pointer to an (<I>n</I> -
1)-dimensional array with rank <I>j</I> &#215; ... &#215;
<I>k</I>.

</BLOCKQUOTE>

<P>This formulation does not allow for the existence of expressions
in which the array-to-pointer conversion does <I>not</I> occur
(as specified in Clause 7 [<A href="https://wg21.link/expr#9">expr</A>] paragraph 9).  This
paragraph should be no more than a note, if it appears at all, and
the wording should be corrected.</P>

<P><B>Proposed resolution (November, 2009):</B></P>

<P>Change paragraphs 6-8 of 9.3.4.5 [<A href="https://wg21.link/dcl.array">dcl.array</A>] into a
note and make the indicated changes:</P>

<BLOCKQUOTE>

<P>
<INS>[<I>Note:</I> </INS>Except where it has been declared for
a class (12.4.5 [<A href="https://wg21.link/over.sub">over.sub</A>]), the subscript operator
<TT>[]</TT> is interpreted in such a way that <TT>E1[E2]</TT> is
identical to <TT>*((E1)+(E2))</TT>. Because of the conversion
rules that apply to <TT>+</TT>, if <TT>E1</TT> is an array and
<TT>E2</TT> an integer, then <TT>E1[E2]</TT> refers to the
<TT>E2</TT>-th member of <TT>E1</TT>.  Therefore, despite its
asymmetric appearance, subscripting is a commutative
operation.</P>

<P>A consistent rule is followed for multidimensional arrays. If
<TT>E</TT> is an <I>n</I>-dimensional array of rank <I>i</I> &#215;
<I>j</I> &#215; .&#160;.&#160;. &#215; <I>k</I>, then
<TT>E</TT> appearing in an expression <INS>that is subject to the
array-to-pointer conversion (7.3.3 [<A href="https://wg21.link/conv.array">conv.array</A>])</INS> is
converted to a pointer to an (<I>n</I>-1)-dimensional array with
rank <I>j</I> &#215; .&#160;.&#160;. &#215; <I>k</I>.  If the
<TT>*</TT> operator, either explicitly or implicitly as a result
of subscripting, is applied to this pointer, the result is the
pointed-to (<I>n</I>-1)-dimensional array, which itself is
immediately converted into a pointer.</P>

<P>[<I>Example:</I> consider</P>

<UL><TT>int x[3][5];</TT></UL>

<P>Here <TT>x</TT> is a 3 &#215; 5 array of integers.  When
<TT>x</TT> appears in an expression, it is converted to a pointer to
(the first of three) five-membered arrays of integers.  In the
expression <TT>x[i]</TT> which is equivalent to <TT>*(x+i)</TT>,
<TT>x</TT> is first converted to a pointer as described; then
<TT>x+i</TT> is converted to the type of <TT>x</TT>, which involves
multiplying <TT>i</TT> by the length of the object to which the
pointer points, namely five integer objects. The results are added and
indirection applied to yield an array (of five integers), which in
turn is converted to a pointer to the first of the integers. If there
is another subscript the same argument applies again; this time the
result is an integer.  &#8212;<I>end example</I>]<INS> &#8212;<I>end
note</I>]</INS>
</P>

</BLOCKQUOTE>

<BR><BR>
</BODY>
</HTML>
