Topic: Sequence points and declarations


Author: comeau@panix.com (Greg Comeau)
Date: Mon, 5 Mar 2001 09:11:55 GMT
Raw View
In article <86u259r3n8.fsf@alex.gabi-soft.de>,
James Kanze  <kanze@gabi-soft.de> wrote:
>comeau@panix.com (Greg Comeau) writes:
>|>  In article <wrcn6.15101$68.1851644@typhoon.tampabay.rr.com>,
>|>  Scott Robert Ladd <scott@coyotegulch.com> wrote:
>|>  >In the following line of code:
>|>  >    int a = 0, b = 1;
>|>  >am I correct in stating that the comma defines a sequence point
>|>  >between the creation and initialization of "a" and "b"?
>|>  >I'm sure this is covered in the standard somewhere, but I couldn't
>|>  >find an appropriate reference when someone challenged me on this
>|>  >issue. While I have faith that I'm correct, I'd like to support my
>|>  >belief with a citation or two... ;)
>
>|>  I don't have a citation but the above is a declaration, therefore
>|>  the comma above is just punctuation, and not the comma operator too,
>|>  therefore, there is no sequence point from the comma per se.  I
>|>  suppose it could be argued that the initialization of a needs to be
>|>  committed, but the comma above is still not the comma operator.
>
>There is a sequence point, but not because of the comma.  The
>initialization expression is not part of a larger expression, so it is a
>complete expression.  And there is a sequence point at the end of each
>complete expression.

I probably focused too much on the comma not being the comma operator
in my response.  I wholeheartedly agree with you that there is a
sequence point for the reason you state.
--
Greg Comeau                   Comeau C/C++ 4.2.45 "so close"
ONLINE COMPILER ==>           http://www.comeaucomputing.com/tryitout
4.2.45.2 during March!        NEW ONLINE: Try out our C99 mode!
comeau@comeaucomputing.com    http://www.comeaucomputing.com

---
[ 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.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "Scott Robert Ladd" <scott@coyotegulch.com>
Date: Thu, 1 Mar 2001 06:43:32 GMT
Raw View
In the following line of code:

    int a = 0, b = 1;

am I correct in stating that the comma defines a sequence point between the
creation and initialization of "a" and "b"?

I'm sure this is covered in the standard somewhere, but I couldn't find an
appropriate reference when someone challenged me on this issue. While I have
faith that I'm correct, I'd like to support my belief with a citation or
two... ;)

--
Scott Robert Ladd
http://www.coyotegulch.com


---
[ 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.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: comeau@panix.com (Greg Comeau)
Date: Thu, 1 Mar 2001 18:16:58 GMT
Raw View
In article <wrcn6.15101$68.1851644@typhoon.tampabay.rr.com>,
Scott Robert Ladd <scott@coyotegulch.com> wrote:
>In the following line of code:
>
>    int a = 0, b = 1;
>
>am I correct in stating that the comma defines a sequence point between the
>creation and initialization of "a" and "b"?
>
>I'm sure this is covered in the standard somewhere, but I couldn't find an
>appropriate reference when someone challenged me on this issue. While I have
>faith that I'm correct, I'd like to support my belief with a citation or
>two... ;)

I don't have a citation but the above is a declaration,
therefore the comma above is just punctuation,
and not the comma operator too, therefore, there is no sequence
point from the comma per se.  I suppose it could be argued
that the initialization of a needs to be committed,
but the comma above is still not the comma operator.
--
Greg Comeau                   Comeau C/C++ 4.2.44 "so close"
ONLINE COMPILER ==>           http://www.comeaucomputing.com/tryitout
4.2.45 during February!       NEW ONLINE: Try out our C99 mode!
comeau@comeaucomputing.com    http://www.comeaucomputing.com

---
[ 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.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "William M. Miller" <wmmiller@MailAndNews.com>
Date: Thu, 1 Mar 2001 21:36:17 GMT
Raw View
>===== Original Message From "Scott Robert Ladd" <scott@coyotegulch.com> =====
>In the following line of code:
>
>    int a = 0, b = 1;
>
>am I correct in stating that the comma defines a sequence point between the
>creation and initialization of "a" and "b"?
>
>I'm sure this is covered in the standard somewhere, but I couldn't find an
>appropriate reference when someone challenged me on this issue. While I have
>faith that I'm correct, I'd like to support my belief with a citation or
>two... ;)

Yes and no.  There is a sequence point between the initialization of a
and the initialization of b, but it's not there because of the comma.
It's because the two initializer expressions are separate, that is, they
are "full-expressions."

1.9p12:

        A full-expression is an expression that is not a subexpression
        of another expression.

1.9p16:

        There is a sequence point at the completion of evaluation of each
        full-expression.

Since an init-declarator-list is not an expression, the initializers are
each full-expressions.

-- William M. Miller

---
[ 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.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "Anthony Williams" <anthwil@nortelnetworks.com>
Date: Fri, 2 Mar 2001 00:07:37 GMT
Raw View
"Scott Robert Ladd" <scott@coyotegulch.com> wrote in message
news:wrcn6.15101$68.1851644@typhoon.tampabay.rr.com...
> In the following line of code:
>
>     int a = 0, b = 1;
>
> am I correct in stating that the comma defines a sequence point between
the
> creation and initialization of "a" and "b"?

This is a declaration, and so the comma operator is irrelevant here.
However, it is equivalent to

int a=0;
int b=1;

8p3 (Declarators) [dcr.decl]:

"Each init-declarator in a declaration is analyzed separately as if it was
in a declaration by itself."

The only exception is if the name of one of the objects is the same as the
type name (footnote 85)

A better example is

int a,b;

a=0,b=1;

In this case, the comma operator is used

> I'm sure this is covered in the standard somewhere, but I couldn't find an
> appropriate reference when someone challenged me on this issue. While I
have
> faith that I'm correct, I'd like to support my belief with a citation or
> two... ;)

5.18p1: (Comma Operator) [expr.comma]

"A pair of expressions separated by a comma is evaluated left-to-right and
the value of the left expression is discarded. .... All side effects of the
left expression, except for the destruction of temporaries, are performed
before the evaluation of the right expression."

It is the evaluation of side effects which defines a sequence point. Hence
the builtin comma operator defines a sequence point between the left and
right expressions.

However, a user-defined comma operator does NOT have a sequence point
between the operands.

Anthony
--
Anthony Williams
Software Engineer, Nortel Networks Optoelectronics
The opinions expressed in this message are not necessarily those of my
employer



---
[ 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.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: Sun, 4 Mar 2001 04:12:38 GMT
Raw View
Scott Robert Ladd wrote:
>
> In the following line of code:
>
>     int a = 0, b = 1;
>
> am I correct in stating that the comma defines a sequence point between the
> creation and initialization of "a" and "b"?

Not all occurrences of comma are comma operators. In this particular
case, the comma is merely part  of the declaration syntax, and as such
does not have an associated sequence point. However, the comma happens
to mark the end of a full-expression, namely the expression which is
used to initialize a. There is a sequence point at the end of each
full-expression (1.9p16).

---
[ 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.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: James Kanze <kanze@gabi-soft.de>
Date: Sun, 4 Mar 2001 18:20:31 GMT
Raw View
comeau@panix.com (Greg Comeau) writes:

|>  In article <wrcn6.15101$68.1851644@typhoon.tampabay.rr.com>,
|>  Scott Robert Ladd <scott@coyotegulch.com> wrote:
|>  >In the following line of code:

|>  >    int a = 0, b = 1;

|>  >am I correct in stating that the comma defines a sequence point
|>  >between the creation and initialization of "a" and "b"?

|>  >I'm sure this is covered in the standard somewhere, but I couldn't
|>  >find an appropriate reference when someone challenged me on this
|>  >issue. While I have faith that I'm correct, I'd like to support my
|>  >belief with a citation or two... ;)

|>  I don't have a citation but the above is a declaration, therefore
|>  the comma above is just punctuation, and not the comma operator too,
|>  therefore, there is no sequence point from the comma per se.  I
|>  suppose it could be argued that the initialization of a needs to be
|>  committed, but the comma above is still not the comma operator.

There is a sequence point, but not because of the comma.  The
initialization expression is not part of a larger expression, so it is a
complete expression.  And there is a sequence point at the end of each
complete expression.

--
James Kanze                               mailto:kanze@gabi-soft.de
Conseils en informatique orient   e objet/
                   Beratung in objektorientierter Datenverarbeitung
Ziegelh   ttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627

---
[ 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.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]