<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 351</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="351"></A><H4>351.
  
Sequence point error: unspecified or undefined?
</H4>
<B>Section: </B>Clause 7&#160; [<A href="https://wg21.link/expr">expr</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Andrew Koenig
 &#160;&#160;&#160;

 <B>Date: </B>23 April 2002<BR>


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



<P>I have found what looks like a bug in Clause 7 [<A href="https://wg21.link/expr">expr</A>],
paragraph 4:</P>
<BLOCKQUOTE>
   Between the previous and next sequence point a scalar object shall
   have its stored value modified at most once by the evaluation of an
   expression.  Furthermore, the prior value shall be accessed only to
   determine the value to be stored.  The requirements of this
   paragraph shall be met for each allowable ordering of the
   subexpressions of a full expression; otherwise the behavior is
   undefined.  Example:
<PRE>
        i = v[i++];                     // the behavior is unspecified
        i = 7, i++, i++;                // i becomes 9

        i = ++i + 1;                    // the behavior is unspecified
        i = i + 1;                      // the value of i is incremented
</PRE>
   --end example]
</BLOCKQUOTE>

<P>So which is it, unspecified or undefined?</P>

<P><B>Notes from October 2002 meeting:</B></P>

<P>We should find out what C99 says and do the same thing.</P>

<P><B>Proposed resolution (April 2003):</B></P>

<P>Change the example in Clause 7 [<A href="https://wg21.link/expr">expr</A>], paragraph 4 from</P>

<BLOCKQUOTE>
[<I>Example:</I>
<PRE>
i = v[i++];                     //<I>  the behavior is unspecified</I>
i = 7, i++, i++;                //<I>   </I>i<I>  becomes  </I>9

i = ++i + 1;                    //<I>  the behavior is unspecified</I>
i = i + 1;                      //<I>  the value of  </I>i<I>  is incremented</I>
</PRE>
--- end example]
</BLOCKQUOTE>

<P>to (changing "unspecified" to "undefined" twice)</P>

<BLOCKQUOTE>
[<I>Example:</I>
<PRE>
i = v[i++];                     //<I>  the behavior is undefined</I>
i = 7, i++, i++;                //<I>   </I>i<I>  becomes  </I>9

i = ++i + 1;                    //<I>  the behavior is undefined</I>
i = i + 1;                      //<I>  the value of  </I>i<I>  is incremented</I>
</PRE>
--- end example]
</BLOCKQUOTE>

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