Topic: Is the right-hand side of a comma operator expression fully evaluted?
Author: ben-public-nospam@decadentplace.org.uk (Ben Hutchings)
Date: Tue, 13 Dec 2005 05:17:08 GMT Raw View
<kuyper@wizard.net> wrote:
<snip>
> There's a sequence point at the end of every full expression (1.9p16).
> Unfortunately, the C++ standard doesn't define what a full expression
> is.
<snip>
It does, in paragraph 12.
--
Ben Hutchings
If more than one person is responsible for a bug, no one is at fault.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "Tom Widmer" <tom_usenet@hotmail.com>
Date: Mon, 12 Dec 2005 23:16:07 CST Raw View
kuyper@wizard.net wrote:
> Razzer wrote:
> There's a sequence point at the end of every full expression (1.9p16).
> Unfortunately, the C++ standard doesn't define what a full expression
> is.
It does: 1.9/12
Tom
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kuyper@wizard.net
Date: Tue, 13 Dec 2005 09:37:39 CST Raw View
Tom Widmer wrote:
> kuyper@wizard.net wrote:
> > Razzer wrote:
>
> > There's a sequence point at the end of every full expression (1.9p16).
> > Unfortunately, the C++ standard doesn't define what a full expression
> > is.
>
> It does: 1.9/12
Thanks! I use Adobe Acrobat v5.0 for Linux to view the PDF file, and it
doesn't handle "-" characters in searches properly. Searches for
"full-expression" didn't produce any results, and searches for "full
expression" didn't identify 1.9p12. Does anyone know if this has been
fixed in later versions?
The C++ definition of "full-expression" differs from the C definition,
in that it does not exempt expressions that occur in declarators.
Therefore, C++ doesn't need a seperate statement that there's a
sequence point at the end of full declarators, the way that the C
standard does. Therefore, the problem I was worried about doesn't
exist.
Every comma expression, no matter where it occurs, is followed sooner
or later by another sequence point. It's at that sequence point (and no
sooner!) that you are guaranteed that the side effects of the right
operand have completed.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: Niklas Matthies <usenet-nospam@nmhq.net>
Date: Tue, 13 Dec 2005 23:56:22 CST Raw View
On 2005-12-13 15:37, kuyper@wizard.net wrote:
:
> I use Adobe Acrobat v5.0 for Linux to view the PDF file, and it
> doesn't handle "-" characters in searches properly. Searches for
> "full-expression" didn't produce any results, and searches for "full
> expression" didn't identify 1.9p12. Does anyone know if this has been
> fixed in later versions?
Searching for "fullexpression" does the trick in Adobe Reader 7.0.
-- Niklas Matthies
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: jpotter@lhup.edu (John Potter)
Date: Wed, 14 Dec 2005 05:56:10 GMT Raw View
On Tue, 13 Dec 2005 09:37:39 CST, kuyper@wizard.net wrote:
> Thanks! I use Adobe Acrobat v5.0 for Linux to view the PDF file, and it
> doesn't handle "-" characters in searches properly. Searches for
> "full-expression" didn't produce any results, and searches for "full
> expression" didn't identify 1.9p12.
The '-' is invisible, maybe considered to be a line break. Search for
"fullexpression" to find them.
John
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "Razzer" <coolmandan@gmail.com>
Date: Thu, 8 Dec 2005 22:54:47 CST Raw View
I was reading the C++ standard (2003), and I was looking at sequence
points. I went to the comma operator and read up on it. The standard
clearly states that all side effects on the left-hand side of the comma
expression are fully-evaluated before the right-hand side is executed.
As a reference to my question, here is 5.18:
A pair of expressions separated by a comma is evaluated left-to-right
and the value of the left expression is
discarded. The lvalue-to-rvalue (4.1), array-to-pointer (4.2), and
function-to-pointer (4.3) standard conversions
are not applied to the left expression. All side effects (1.9) of the
left expression, except for the
destruction of temporaries (12.2), are performed before the evaluation
of the right expression. The type and
value of the result are the type and value of the right operand; the
result is an lvalue if its right operand is.
Is the right-hand side of a comma expression fully evaluated (hence,
all side effects have occured)? As far as I can tell, it is definately
not guaranteed that the right hand side of a comma expression is
fully-evaluated.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: francis@robinton.demon.co.uk (Francis Glassborow)
Date: Fri, 9 Dec 2005 16:06:25 GMT Raw View
In article <1134073171.498892.93010@g47g2000cwa.googlegroups.com>,
Razzer <coolmandan@gmail.com> writes
>Is the right-hand side of a comma expression fully evaluated (hence,
>all side effects have occured)? As far as I can tell, it is definately
>not guaranteed that the right hand side of a comma expression is
>fully-evaluated.
The guarantee is the same as it is for any code, it will be fully
evaluated and side effects complete before the next sequence point. The
real nastiness about the comma operators (as for the logical & and |) is
that user defined versions do not have the same guarantee (though it is,
IMO, nastier in the case of the logical operators because of the issue
of lazy evaluation)
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kuyper@wizard.net
Date: Fri, 9 Dec 2005 10:08:01 CST Raw View
Razzer wrote:
> I was reading the C++ standard (2003), and I was looking at sequence
> points. I went to the comma operator and read up on it. The standard
> clearly states that all side effects on the left-hand side of the comma
> expression are fully-evaluated before the right-hand side is executed.
> As a reference to my question, here is 5.18:
>
> A pair of expressions separated by a comma is evaluated left-to-right
> and the value of the left expression is
> discarded. The lvalue-to-rvalue (4.1), array-to-pointer (4.2), and
> function-to-pointer (4.3) standard conversions
> are not applied to the left expression. All side effects (1.9) of the
> left expression, except for the
> destruction of temporaries (12.2), are performed before the evaluation
> of the right expression. The type and
> value of the result are the type and value of the right operand; the
> result is an lvalue if its right operand is.
>
> Is the right-hand side of a comma expression fully evaluated (hence,
> all side effects have occured)? As far as I can tell, it is definately
> not guaranteed that the right hand side of a comma expression is
> fully-evaluated.
At the sequence point associated with the comma expression, there is in
fact no guarantee that the right operand is fully evaluated. You should
not write code that assumes that it is. However, the right operand of
the comma operator is absolutely guaranteed to be fully evaluated at
the next sequence point.
There's a sequence point at the end of every full expression (1.9p16).
Unfortunately, the C++ standard doesn't define what a full expression
is. In C, a full expression is any expression that isn't part of some
other expression or declarator. In C there's also a sequence point at
the end of every full declarator, so every expression has a sequence
point that follows it, sooner or later. I may be missing something, but
I can't find the corresponding wording in the C++ standard. Without a
definition of full expression, and without a sequence point at the end
of a declarator, it's not entirely clear that the side effects of an
initialization expression are completed at the location where, from my
C experience, I would expect them to be:
int i=0;
int j = i++; // Does 'i' ever have to be incremented? If so, when, and
why?
void myfunc(int k)
{
int l = k++;
// The next sequence point after k++ is the one at the end of the
following statement:
cout << k << endl;
// is it legal for myfunc(0) to print out '0'?
}
I hope someone can point out something to me that I've missed that
makes this conclusion invalid.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "vish" <vishakha@gmail.com>
Date: Fri, 9 Dec 2005 10:06:59 CST Raw View
The comma operator has left to right associativity. The use of the
comma operator guarantees that the subexpressions will be evaluated in
left-to-right order, and the value of the last becomes the value of the
entire expression. So RHS of the comma operator has to be evaluated,
unless the left expression results in some exception.
-Vish
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]