x=(r,s,t);

J

James Kuyper

Joachim said:
Ben Bacarisse wrote: ....
for ( /declaration/ /expression/<opt> ; /expression/<opt> )
/statement/
[If your news reader does not so /italics/ this will look odd.
Sorry.]

Which newsreader does?

Mine (Thunderbird) does.
 
T

Tim Rentsch

Ben Bacarisse said:
Harald van Dijk said:
I missed something here, sorry. The first comma above is not the comma
operator. The second comma is.

[I chipped in with the same point when I thought the thread had left
the topic. I should have just read to the end.]
There is a sequence point after the
evaluation of "0" and "10" in "int x=0, y=10", but I believe there is no
requirement that "0" is evaluated before "10".

In other words,

int a=1;
int b=++a, c=++a;

must set b and c to 2 and 3, or to 3 and 2, and there is no requirement
that the implementation is consistent in how it chooses.

Corrections welcome, because it's very well possible I'm overlooking
something here.

I can't be sure enough to offer a correction, but I had always assumed
that the sequence point at the end of a full declarator was to permit
(in a meaningful way):

int x = 1, y = x + 1;

If so, then your example must give b == 2 and c == 3.

This point is addressed in 6.8p2:

A block allows a set of declarations and statements to be grouped
into one syntactic unit. The initializers of objects that have
automatic storage duration, and the variable length array
declarators of ordinary identifiers with block scope, are
evaluated and the values are stored in the objects (including
storing an indeterminate value in objects without an initializer)
each time the declaration is reached in the order of execution,
as if it were a statement, /and within each declaration in the
order that declarators appear./ [emphasis added]

The last clause specifies evaluation order for declarators within
a single declaration for automatic variables, including (even
if somewhat obliquely) declarators in for() statements.
Presumably file scope declarations and 'static' declarations
within functions don't need such guarantees because the
requirements for their initializers (being constant expressions)
prevent any side effects from taking place.
 
S

Stephen Sprunk

Joachim said:
Isn't this C++ rather than C? Or did I miss that C99 introduced it?

You mean the embedded declarations? That is indeed a C99ism (though I
learned it as a GCCism).
Is the ", " above really the comma operator?

The second comma is clearly a comma operator; there is a sequence point
between "x++" and "y--".

The reason this is a common use for the comma operator is that, unlike
in most other contexts, a semicolon cannot be used here for that purpose.
> AFAIR the ";" in the for() is not a sequencw point as if used to
finish a statement.

No, but IIRC there is a sequence point before and after each of the
three expressions in a for() anyways; that a semicolon is used to
separate them just makes it a bit more confusing as to which rule applies.

S
 
H

Harald van Dijk

Ben Bacarisse said:
I can't be sure enough to offer a correction, but I had always assumed
that the sequence point at the end of a full declarator was to permit
(in a meaningful way):

int x = 1, y = x + 1;

If so, then your example must give b == 2 and c == 3.

This point is addressed in 6.8p2:
[...]

So it is. Thank you, I had missed that.
The last clause specifies evaluation order for declarators within a
single declaration for automatic variables, including (even if somewhat
obliquely) declarators in for() statements. Presumably file scope
declarations and 'static' declarations within functions don't need such
guarantees because the requirements for their initializers (being
constant expressions) prevent any side effects from taking place.

Right. That explains why this order of evaluation can be specified under
statements rather than declarations: it's specified as a property of the
statements that the declarations appear in, rather than of the
declarations themselves, because all declarations it applies to -- those
with automatic storage duration -- are part of a statement.
 
K

Keith Thompson

James Kuyper said:
Joachim said:
Ben Bacarisse wrote: ...
for ( /declaration/ /expression/<opt> ; /expression/<opt> )
/statement/
[If your news reader does not so /italics/ this will look odd.
Sorry.]
Which newsreader does?

Mine (Thunderbird) does.

Really? So if I write, say, a directory path /etc/ it puts "etc" in
italics rather than showing you the '/' characters? If my newsreader
did that, I'd look for a way to turn it off or a new newsreader.
 
R

Richard

Keith Thompson said:
James Kuyper said:
Joachim said:
Ben Bacarisse wrote: ...
for ( /declaration/ /expression/<opt> ; /expression/<opt> )
/statement/
[If your news reader does not so /italics/ this will look odd.
Sorry.]
Which newsreader does?

Mine (Thunderbird) does.

Really? So if I write, say, a directory path /etc/ it puts "etc" in
italics rather than showing you the '/' characters? If my newsreader
did that, I'd look for a way to turn it off or a new newsreader.

Gnus does indeed do this. Well, in non antiquated versions. You should
consider moving up to Emacs 22 at least.
 
S

Stephen Sprunk

Keith said:
James Kuyper said:
Joachim said:
Ben Bacarisse wrote: ...
for ( /declaration/ /expression/<opt> ; /expression/<opt> )
/statement/
[If your news reader does not so /italics/ this will look odd.
Sorry.]

Which newsreader does?

Mine (Thunderbird) does.

Really? So if I write, say, a directory path /etc/ it puts "etc" in
italics rather than showing you the '/' characters?

It doesn't remove the / characters; they and the text they enclose are
simply italicized, which is easy enough to ignore when it's incorrect.

Also, the italics (or *bold* or _underline_) only apply when the special
characters appear at the start and end of words; most folks write /etc,
not /etc/, and the former will not get italics.
If my newsreader did that, I'd look for a way to turn it off or a
new newsreader.

The feature can be disabled easily enough if you don't like it, just
like one can disable conversion of emoticons (which does, on occasion,
erase valid punctuation). It's a popular feature, though.

S
 
P

Phil Carmody

MisterE said:
Its interesting that the comma operator is so seldom used, even in its only
usual place in for(;;).
I once saw some code that , joined every possible line it could. Not sure
why.

That was a response to a company coding standard which said "A
function may only have one return statement" and which was
interpreted ultra-literally. I hope you enjoyed maintaining
that code as much as I enjoyed writing it!

Phil
 
K

Keith Thompson

Phil Carmody said:
That was a response to a company coding standard which said "A
function may only have one return statement" and which was
interpreted ultra-literally. I hope you enjoyed maintaining
that code as much as I enjoyed writing it!

What does using comma operators rather than semicolons have to do with
having only one return statement? (Unless you mean that it was used
to ensure that the function had only one *statement* which isn't an
ultra-literal interpretation at all, just a wrong one.)
 
P

Phil Carmody

Keith Thompson said:
What does using comma operators rather than semicolons have to do with
having only one return statement? (Unless you mean that it was used
to ensure that the function had only one *statement* which isn't an
ultra-literal interpretation at all, just a wrong one.)

Au contraire. For example, if, as an external contractor in a
free staff canteen, you "may only have one plateful of main
course", then you appear to think that you can have an unbounded
quantity of dessert too to accompany said single plate of main
course. Such is not the common interpretation of the English
phrase "may only have one <X>".

You appear to be confusing it with "may have only one <X>",
where the "only" modifies a different semantic element, and
consequently has a different meaning.

Phil
 
J

James Kuyper

Keith said:
James Kuyper said:
Joachim said:
Ben Bacarisse wrote: ...
for ( /declaration/ /expression/<opt> ; /expression/<opt> )
/statement/
[If your news reader does not so /italics/ this will look odd.
Sorry.]
Which newsreader does?
Mine (Thunderbird) does.

Really? So if I write, say, a directory path /etc/ it puts "etc" in
italics rather than showing you the '/' characters?

No, it displays it in italics while also showing the '/' characters.
I've never noticed this until Joachim's question made me actually check.
 
M

Mark Wooding

Joachim Schmitz said:
Ben said:
[If your news reader does not so /italics/ this will look odd.
Sorry.]

Which newsreader does?

Gnus for one, if you run it under a window system. (I run my Gnus in
screen, so I get visible slashes.)

-- [mdw]
 
J

J. J. Farrell

Stephen said:
Keith said:
James Kuyper said:
Joachim Schmitz wrote:
Ben Bacarisse wrote:
...
for ( /declaration/ /expression/<opt> ; /expression/<opt> )
/statement/
[If your news reader does not so /italics/ this will look odd.
Sorry.]

Which newsreader does?

Mine (Thunderbird) does.

Really? So if I write, say, a directory path /etc/ it puts "etc" in
italics rather than showing you the '/' characters?

It doesn't remove the / characters; they and the text they enclose are
simply italicized, which is easy enough to ignore when it's incorrect.

Also, the italics (or *bold* or _underline_) only apply when the special
characters appear at the start and end of words; most folks write /etc,
not /etc/, and the former will not get italics.
If my newsreader did that, I'd look for a way to turn it off or a
new newsreader.

The feature can be disabled easily enough if you don't like it, just
like one can disable conversion of emoticons (which does, on occasion,
erase valid punctuation). It's a popular feature, though.

It's a very long-standing concept ... these three have been standard
Usenet markup since the dawn of time (or soon after). I don't know when
newsreaders started displaying the formats, but for terminals capable of
doing so I assume it was about the same time as the markup came in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,200
Latest member
LaraHunley

Latest Threads

Top