niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » C
x=(x=5,11)
Post new topic   Reply to topic Page 1 of 8 [112 Posts] View previous topic :: View next topic
Goto page:  1, 2, 3, ..., 6, 7, 8 Next
Author Message
Robert Gamble
*nix forums Guru


Joined: 15 Apr 2005
Posts: 447

PostPosted: Sat May 27, 2006 4:31 am    Post subject: Re: x=(x=5,11) Reply with quote

Jordan Abel wrote:
Quote:
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?

Here is the operation in question copied from the subject line:
x=(x=5,11);
It looks defined to me, there is a sequence point between the
assignments. What is your argument for it being undefined?

Robert Gamble
Back to top
Jordan Abel
*nix forums Guru


Joined: 25 Oct 2005
Posts: 1366

PostPosted: Sat May 27, 2006 4:32 am    Post subject: Re: x=(x=5,11) Reply with quote

On 2006-05-27, Robert Gamble <rgamble99@gmail.com> wrote:
Quote:
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?

Here is the operation in question copied from the subject line:
x=(x=5,11);
It looks defined to me, there is a sequence point between the
assignments. What is your argument for it being undefined?

How is there a sequence point between "x=5" and "x=<inner_expression>"?
the only sequence point i see is between "x=5" and "11"

Quote:

Robert Gamble
Back to top
Robert Gamble
*nix forums Guru


Joined: 15 Apr 2005
Posts: 447

PostPosted: Sat May 27, 2006 4:52 am    Post subject: Re: x=(x=5,11) Reply with quote

Jordan Abel wrote:
Quote:
On 2006-05-27, Robert Gamble <rgamble99@gmail.com> wrote:
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?

Here is the operation in question copied from the subject line:
x=(x=5,11);
It looks defined to me, there is a sequence point between the
assignments. What is your argument for it being undefined?

How is there a sequence point between "x=5" and "x=<inner_expression>"?
the only sequence point i see is between "x=5" and "11"

The RHS of the expression must be evaluated to determine the value to
store in x, in that expression there is a sequence point after which x
is not modifed before the value of the subexpression is stored into x.

Robert Gamble
Back to top
CBFalconer
*nix forums Guru


Joined: 09 Mar 2005
Posts: 2502

PostPosted: Sat May 27, 2006 4:58 am    Post subject: Re: x=(x=5,11) Reply with quote

Jordan Abel wrote:
Quote:

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.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
Back to top
Frodo Baggins
*nix forums beginner


Joined: 21 Sep 2005
Posts: 15

PostPosted: Sat May 27, 2006 5:38 am    Post subject: Re: x=(x=5,11) Reply with quote

Jordan Abel wrote:
Quote:
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 am not sure, but comma has lower precedence than assignment.
hence the assignment x=5 occurs then due to comma, 11 is the value of
the expression
x=5,11 and this is assigned to x.

However if I remove the parantheses, gcc gives a warning that the
operation on x may be undefined.

Also assignment operator does not define a sequence point but the end
of each operand of the comma operator does.

Regards,
Frodo Baggins
Back to top
Jordan Abel
*nix forums Guru


Joined: 25 Oct 2005
Posts: 1366

PostPosted: Sat May 27, 2006 6:03 am    Post subject: Re: x=(x=5,11) Reply with quote

On 2006-05-27, Robert Gamble <rgamble99@gmail.com> wrote:
Quote:
Jordan Abel wrote:
On 2006-05-27, Robert Gamble <rgamble99@gmail.com> wrote:
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?

Here is the operation in question copied from the subject line:
x=(x=5,11);
It looks defined to me, there is a sequence point between the
assignments. What is your argument for it being undefined?

How is there a sequence point between "x=5" and "x=<inner_expression>"?
the only sequence point i see is between "x=5" and "11"

The RHS of the expression must be evaluated to determine the value to
store in x

Says who? The compiler already knows the final value of the expression.

Quote:
, in that expression there is a sequence point after which x
is not modifed before the value of the subexpression is stored into x.

= is not a sequence point. By what authority do you claim that one thing
"must" be evaluated before another without a sequence point?
Back to top
Jordan Abel
*nix forums Guru


Joined: 25 Oct 2005
Posts: 1366

PostPosted: Sat May 27, 2006 6:09 am    Post subject: Re: x=(x=5,11) Reply with quote

On 2006-05-27, CBFalconer <cbfalconer@yahoo.com> wrote:
Quote:
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.
Back to top
Default User
*nix forums Guru


Joined: 21 Feb 2005
Posts: 1159

PostPosted: Sat May 27, 2006 6:14 am    Post subject: Re: x=(x=5,11) Reply with quote

CBFalconer wrote:

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

Well, as his headers indicate:

User-Agent: slrn/0.9.8.1 (FreeBSD)


I don't think Google enters into it.




Brian
Back to top
pete
*nix forums Guru


Joined: 09 Apr 2005
Posts: 1757

PostPosted: Sat May 27, 2006 7:48 am    Post subject: Re: x=(x=5,11) Reply with quote

Jordan Abel wrote:
Quote:

On 2006-05-27, Robert Gamble <rgamble99@gmail.com> wrote:

, in that expression there is a sequence point after which x
is not modifed before the value
of the subexpression is stored into x.

= is not a sequence point.
By what authority do you claim that one thing
"must" be evaluated before another without a sequence point?

I'm starting to see this, Jordan Abel's way.

6.5 Expressions
[#3] The grouping of operators and operands is indicated by
the syntax.61) Except as specified later (for the function-
call (), &&, ||, ?:, and comma operators), the order of
evaluation of subexpressions and the order in which side
effects take place are both unspecified.

The assignment expression itself, is a sequence point,
but the operands of the assignment operator are subexpressions.

--
pete
Back to top
Keith Thompson
*nix forums Guru


Joined: 28 Feb 2005
Posts: 5173

PostPosted: Sat May 27, 2006 8:08 am    Post subject: Re: x=(x=5,11) Reply with quote

CBFalconer <cbfalconer@yahoo.com> writes:
[...]
Quote:
BTW don't rely on the subject being visible when reading the
article. It often isn't. Google is not usenet.

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.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Back to top
neutron*star
*nix forums Guru


Joined: 21 Feb 2005
Posts: 2039

PostPosted: Sat May 27, 2006 8:50 am    Post subject: Re: x=(x=5,11) Reply with quote

Jordan Abel said:

Quote:
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 and
to improve clarity, and I would recommend doing this at the earliest
possibility.

In this respect, it's similar to the p = p->next = q; debate that we had a
few years ago.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Back to top
pemo
*nix forums Guru


Joined: 04 Aug 2005
Posts: 384

PostPosted: Sat May 27, 2006 8:54 am    Post subject: Re: x=(x=5,11) Reply with quote

Jordan Abel wrote:
Quote:
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

(X=5,11)

X is assigned the value 5, and then the comma comes into play, and the
resulting value of the paraen'ed-expression is 11.

X=11


--
==============
Not a pedant
==============
Back to top
pemo
*nix forums Guru


Joined: 04 Aug 2005
Posts: 384

PostPosted: Sat May 27, 2006 8:56 am    Post subject: Re: x=(x=5,11) Reply with quote

Jordan Abel wrote:
Quote:
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?

Where/what is ##c, I'd be interested in seeing the original conversation?

--
==============
Not a pedant
==============
Back to top
neutron*star
*nix forums Guru


Joined: 21 Feb 2005
Posts: 2039

PostPosted: Sat May 27, 2006 9:04 am    Post subject: Re: x=(x=5,11) Reply with quote

pemo said:

Quote:
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?

Where/what is ##c, I'd be interested in seeing the original conversation?

No chance of that, unless someone kept logs. (Which, indeed, I might have
done! I don't know, but I could look if you care enough.)

He's talking about Freenode's C channel. Any sensible IRC network would call
it #c, so naturally Freenode adds another #, to make it ##c. Curiously,
#foo channels are reserved for those who actually have some kind of
"ownership" of <foo>. So #c is reserved for Dennis Ritchie, I guess, and
possibly the ISO guys. I'm sure they are very grateful. When this change
took effect, however, quite a few of those ejected from #c to make room for
Dennis were, shall we say, rather less grateful - and remain so.

Undernet's #c channel continues to have the more traditional name.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Back to top
pete
*nix forums Guru


Joined: 09 Apr 2005
Posts: 1757

PostPosted: Sat May 27, 2006 9:48 am    Post subject: Re: x=(x=5,11) Reply with quote

Richard Heathfield wrote:
Quote:

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 and
to improve clarity, and I would recommend
doing this at the earliest possibility.

In this respect, it's similar to the p = p->next = q;
debate that we had a few years ago.

I recall that everyone who said that
p = p->next = q;
was defined,
also said that they wouldn't write code that way.

--
pete
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 8 [112 Posts] Goto page:  1, 2, 3, ..., 6, 7, 8 Next
View previous topic :: View next topic
The time now is Fri Jan 09, 2009 4:42 am | All times are GMT
navigation Forum index » Programming » C
Jump to:  


Secured Loans | Image Hosting | Freelance | Remortgages | Home Equity Loan
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1886s ][ Queries: 11 (0.0645s) ][ GZIP on - Debug on ]