x=(x=5,11)

A

Andrew Poelstra

I have no idea what ##c means. However if you are (and you should
be) talking about the C language, then they are right.

BTW don't rely on the subject being visible when reading the
article. It often isn't. Google is not usenet.

Check my headers before accusing me of using google.

On what newsreaders is it not visible? It comes with it along with the
rest of the headers in the NNTP protocol, and any newsreader i've ever
seen has a titlebar or a thread display or displays a subset of the
headers along with the article text.

Mozilla 4.75 [en] (Win98; U) does the last two of those three. It may
also put the subject in the titlebar, i can't tell from the screenshots
i've found (you certainly seemed to identify the subject line well
enough.) Were you just being difficult? Maybe you should have been
prepared with an example of a newsreader that doesn't display the
subject, instead of assuming I was some google-using moron who would
blindly accept any outrageous claim about what newsreaders exist in the
world.

Once I used telnet to read clc, just to see if I understood NNTP well
enough. I piped the output through awk to make a hack custom newsreader.
I can't imagine any claim about newsreaders in the world being "outrageous".

I'm using slrn right now, and the subject is way at the top of my screen.
Reading it would be a pain.
 
J

Jordan Abel

Jordan said:
Is this defined or not? Some people in ##c are saying that it has to
result in x being set to 11, i'm saying it's undefined. Who's right?

x=(X=5,11)

My reading [but what do I know!]

X=paraen'ed-expression

So, paraen'ed-expression must be evaluated first

Why? The compiler doesn't need to emit code to evaluate it to know the value.

I think that the statement

char foo[9];
x=(x=sprintf(foo,"hello"),sprintf(foo," world!\n"));

could do things in this order:

x=8
x=5
set foo to "hello"
set foo to "world!\n"
 
J

Jordan Abel

A conforming implementation cannot introduce undefined behavior when
the semantics of the abstract machine are defined as they are in this
case. If the compiler wants to optimize the expression it must do so
without invoking undefined behavior.

And what part of the standard defines the behavior in this case?

You're introducing a sequence point between the right-hand side of the
assignment operator and the assignment itself. There is no such sequence
point mentioned in the standard. The fact that the standard _does_
define such a sequence point between the evaluation of the arguments to
a function [the right-hand side of the function call operator] and the
call itself, it would appear that if they meant for a sequence point to
be there, they would have said so.

Nowhere does it say that the semantics of the abstract machine include
finishing the evaluation of the right-hand side of the assignment, or
even starting it, before assigning the final value to the variable.
6.5.16.1p2:
"In simple assignment (=), the value of the right operand is converted
to the type of the
assignment expression and replaces the value stored in the object
designated by the left
operand."
Now how is it possible to obtain the value of the right operand and
convert it to the type of the assignment expression without evaluting
it before you store the result in x?

If the right operand is a comma expression with an expression whose
value is known to be constant as its right-most part. See my printf
example in the other post.
 
J

Jordan Abel

Jordan Abel wrote:

Is this defined or not? Some people in ##c are saying that it has to
result in x being set to 11, i'm saying it's undefined. Who's right?

I have no idea what ##c means. However if you are (and you should
be) talking about the C language, then they are right.

BTW don't rely on the subject being visible when reading the
article. It often isn't. Google is not usenet.

Check my headers before accusing me of using google.

On what newsreaders is it not visible? It comes with it along with the
rest of the headers in the NNTP protocol, and any newsreader i've ever
seen has a titlebar or a thread display or displays a subset of the
headers along with the article text.

Mozilla 4.75 [en] (Win98; U) does the last two of those three. It may
also put the subject in the titlebar, i can't tell from the screenshots
i've found (you certainly seemed to identify the subject line well
enough.) Were you just being difficult? Maybe you should have been
prepared with an example of a newsreader that doesn't display the
subject, instead of assuming I was some google-using moron who would
blindly accept any outrageous claim about what newsreaders exist in the
world.

Once I used telnet to read clc, just to see if I understood NNTP well
enough. I piped the output through awk to make a hack custom newsreader.
I can't imagine any claim about newsreaders in the world being "outrageous".

I'm using slrn right now, and the subject is way at the top of my screen.
Reading it would be a pain.

It's not at the top of the message? slrn displays a subset of headers
(including subject) in the message pane, then a blank line, then the
message body.
 
E

ena8t8si

Jordan said:
Is this defined or not? Some people in ##c are saying that it has to
result in x being set to 11, i'm saying it's undefined. Who's right?

The result of x=(x=5,11); is to set x to the value 11, with
no undefined behavior.

If x is volatile, there will be two stores to x, the first store
storing the value 5, the second store storing the value 11.
 
E

ena8t8si

Richard said:
Jordan Abel said:
Is [the expression x=(x=5,11)] defined or not? Some people in ##c
are saying that it has to result in x being set to 11, i'm saying
it's undefined. Who's right?

I would lean towards its being undefined, but I would not be so terribly
surprised if the Battle of the Language Lawyers ended with victory for the
opposing view.

My own take on the subject is rather pragmatic, I'm afraid. The code can
trivially be rewritten to remove the possibility of undefined behaviour ...

Yes it can, by not changing it at all. The behavior is defined, as
written.
 
E

ena8t8si

"In simple assignment (=), the value of the right operand is
converted to the type of the assignment expression and replaces the
value stored in the object designated by the left operand."
Now how is it possible to obtain the value of the right operand and
convert it to the type of the assignment expression without evaluting
it before you store the result in x?

Clearly it's not possible to store the result before evaluating it,
but it's possible (indeed, easy!) to determine the value of (x=5,11)
before performing the assignment of 5 to x.[/QUOTE]

No, it isn't, because of the sequence point rule for the comma
operator.
 
E

ena8t8si

Jordan said:
Jordan said:
Is this defined or not? Some people in ##c are saying that it has to
result in x being set to 11, i'm saying it's undefined. Who's right?

x=(X=5,11)

My reading [but what do I know!]

X=paraen'ed-expression

So, paraen'ed-expression must be evaluated first

Why? The compiler doesn't need to emit code to evaluate it to know the value.

I think that the statement

char foo[9];
x=(x=sprintf(foo,"hello"),sprintf(foo," world!\n"));

could do things in this order:

x=8
x=5
set foo to "hello"
set foo to "world!\n"

You're falling into the trap of arguing what a compiler
might do rather than what a compiler is obliged to do
by the Standard.

The Standard requires that the evaluation of x=sprintf(foo,"hello")
precede the evaluation of sprintf(foo," world!\n"), and that the
evaluation of sprintf(foo," world!\n") precede the assignment
of 8 to x, because it is evaluations that produce values.
 
D

Default User

Keith said:
I've never heard of a newsreader that doesn't display the subject when
displaying the article (which doesn't, of course, mean that such a
newsreader doesn't exist). But regardless of that, it's certainly a
good idea to put the question in the body of the message, not just in
the subject header.

My newsreader has the heading part configurable. If I were to have it
set to not display any header (or not the Subject part) then I'd have
to look up into the message tree.

At any rate, it's usenet standard to not rely on people reading the
subject line to figure out the post.



Brian
 
E

ena8t8si

Jordan said:
And what part of the standard defines the behavior in this case?

You're introducing a sequence point between the right-hand side of the
assignment operator and the assignment itself. ...

Actually, he isn't. Try reading more carefully.
Nowhere does it say that the semantics of the abstract machine include
finishing the evaluation of the right-hand side of the assignment, or
even starting it, before assigning the final value to the variable.

The only way to get a value of out of (x=5,11) is to evaluate the
comma operator per its Semantics. Read section 6.5.17.
 
J

Jordan Abel

Jordan said:
Jordan Abel wrote:
Is this defined or not? Some people in ##c are saying that it has to
result in x being set to 11, i'm saying it's undefined. Who's right?

x=(X=5,11)

My reading [but what do I know!]

X=paraen'ed-expression

So, paraen'ed-expression must be evaluated first

Why? The compiler doesn't need to emit code to evaluate it to know the value.

I think that the statement

char foo[9];
x=(x=sprintf(foo,"hello"),sprintf(foo," world!\n"));

could do things in this order:

x=8
x=5
set foo to "hello"
set foo to "world!\n"

You're falling into the trap of arguing what a compiler
might do rather than what a compiler is obliged to do
by the Standard.

The "as if" rule applies.
 
P

pete

Jordan Abel wrote:
Repeat after me:

Sequence points define a partial ordering.

What I came away with, from the "p = p -> next = q" debate,
was a general principle of avoiding expressions
with multiple assignments involving the same variable.
x=(x=5,11) is one of those.
I think you're correct.
Good luck with your attempts to persuade.
 
T

Tim Woodall

The result of x=(x=5,11); is to set x to the value 11, with
no undefined behavior.

If x is volatile, there will be two stores to x, the first store
storing the value 5, the second store storing the value 11.
Well I disagree. The side effects of x=5 must be evaluated before the
side effects of 11, but nothing requires the side effects of the x=()
assignment to be evaluated after the side effects of the x=5
assignment.

Tim.
 
G

Guest

Jordan Abel wrote:
[x=(x=5,11)]
Is this defined or not? Some people in ##c are saying that it has to
result in x being set to 11, i'm saying it's undefined. Who's right?

To use another example:

#include <stdlib.h>
int main(void) {
int *p = 0;
exit(0), *p;
}

Is this a valid C program?

I believe there is no significant difference between this, and
x=(x=5,11). In both cases, the behaviour is defined if and only if the
right operand of the , operator is not ever evaluated before the left
operand is, in both cases there are no side effects in the evaluation
of the right operand, and in both cases and the question is whether the
as-if rule can introduce undefined behaviour when there would otherwise
not be any. Do you agree that this example has the same problem? And if
not, why not? (The reason I'm using this example is because disallowing
it is much more surprising to me than disallowing your original code.)
 
K

Kenneth Brody

Robert said:
Jordan Abel wrote: [...]
x=(x=5,11);
[...]
= is not a sequence point. By what authority do you claim that one thing
"must" be evaluated before another without a sequence point?

6.5.16.1p2:
"In simple assignment (=), the value of the right operand is converted
to the type of the
assignment expression and replaces the value stored in the object
designated by the left
operand."

Now how is it possible to obtain the value of the right operand and
convert it to the type of the assignment expression without evaluting
it before you store the result in x?

Well, "the value of the right operand" can be determined without
necessarily introducing all of the side effects. Extending that
logic, the following should be "defined" as well:

x = (x++,11);

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 
A

Andrew Poelstra

Jordan Abel wrote:

Is this defined or not? Some people in ##c are saying that it has to
result in x being set to 11, i'm saying it's undefined. Who's right?

I have no idea what ##c means. However if you are (and you should
be) talking about the C language, then they are right.

BTW don't rely on the subject being visible when reading the
article. It often isn't. Google is not usenet.

Check my headers before accusing me of using google.

On what newsreaders is it not visible? It comes with it along with the
rest of the headers in the NNTP protocol, and any newsreader i've ever
seen has a titlebar or a thread display or displays a subset of the
headers along with the article text.

Mozilla 4.75 [en] (Win98; U) does the last two of those three. It may
also put the subject in the titlebar, i can't tell from the screenshots
i've found (you certainly seemed to identify the subject line well
enough.) Were you just being difficult? Maybe you should have been
prepared with an example of a newsreader that doesn't display the
subject, instead of assuming I was some google-using moron who would
blindly accept any outrageous claim about what newsreaders exist in the
world.

Once I used telnet to read clc, just to see if I understood NNTP well
enough. I piped the output through awk to make a hack custom newsreader.
I can't imagine any claim about newsreaders in the world being "outrageous".

I'm using slrn right now, and the subject is way at the top of my screen.
Reading it would be a pain.

It's not at the top of the message? slrn displays a subset of headers
(including subject) in the message pane, then a blank line, then the
message body.

Not once you scroll down, and because I'm usually SSHed onto this machine
over a dial-up equivilant connection, scrolling back up is not a worthy
use of time.

This, however, is complete OT to standard C. You can have the last word
if you want.
 
R

Robert Gamble

Kenneth said:
Robert said:
Jordan Abel wrote: [...]
x=(x=5,11); [...]
= is not a sequence point. By what authority do you claim that one thing
"must" be evaluated before another without a sequence point?

6.5.16.1p2:
"In simple assignment (=), the value of the right operand is converted
to the type of the
assignment expression and replaces the value stored in the object
designated by the left
operand."

Now how is it possible to obtain the value of the right operand and
convert it to the type of the assignment expression without evaluting
it before you store the result in x?

Well, "the value of the right operand" can be determined without
necessarily introducing all of the side effects. Extending that
logic, the following should be "defined" as well:

x = (x++,11);

Right, and it is.

Robert Gamble
 
E

ena8t8si

Jordan said:
Repeat after me:

Sequence points define a partial ordering.

You seem to think that sequence points are the only thing
that affect the partial ordering of expression evaluation.
That's false. In the expression a + b - c, the evaluation
of + must precede the evaluation of - in the abstract
machine. And compiled code must behave as if
the abstract machine would behave.
 
E

ena8t8si

Jordan said:
Jordan said:
Jordan Abel wrote:
Is this defined or not? Some people in ##c are saying that it has to
result in x being set to 11, i'm saying it's undefined. Who's right?

x=(X=5,11)

My reading [but what do I know!]

X=paraen'ed-expression

So, paraen'ed-expression must be evaluated first

Why? The compiler doesn't need to emit code to evaluate it to know the value.

I think that the statement

char foo[9];
x=(x=sprintf(foo,"hello"),sprintf(foo," world!\n"));

could do things in this order:

x=8
x=5
set foo to "hello"
set foo to "world!\n"

You're falling into the trap of arguing what a compiler
might do rather than what a compiler is obliged to do
by the Standard.

The "as if" rule applies.

Yes, and the code you posted doesn't behave as if
it were executed by the abstract machine.
 

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,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top