473,903 Members | 3,336 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?
May 27 '06
111 4952
CBFalconer <cb********@yah oo.com> writes:
[...]
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_Keit h) ks***@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.
May 27 '06 #11
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.

--
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)
May 27 '06 #12
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

(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
==============
May 27 '06 #13
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?

--
==============
Not a pedant
==============
May 27 '06 #14
pemo 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?


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)
May 27 '06 #15
Richard Heathfield wrote:

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
May 27 '06 #16
Richard Heathfield wrote:
pemo 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?
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.)


Ah, thanks Richard, presumably that's why Google has no record of it [it
being a realtime chat kind of thing]!

##c - what with c#, I thought this was some kind of new bastardized C
variant [deviant?]!
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.


--
==============
Not a pedant
==============
May 27 '06 #17
Jordan Abel wrote:
On 2006-05-27, Robert Gamble <rg*******@gmai l.com> wrote:
Jordan Abel wrote:
On 2006-05-27, Robert Gamble <rg*******@gmai l.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_expre ssion>"?
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.


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.
, 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?


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?

Robert Gamble

May 27 '06 #18
In article <11************ **********@j33g 2000cwa.googleg roups.com>,
Robert Gamble <rg*******@gmai l.com> wrote:
>> > x=(x=5,11);
"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. So the text you quote
does not preclude the assignment of 5 to x happening after the
assignment of 11 to x.

-- Richard
May 27 '06 #19
Richard Tobin wrote:
In article <11************ **********@j33g 2000cwa.googleg roups.com>,
Robert Gamble <rg*******@gmai l.com> wrote:
>> > x=(x=5,11);

"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. So the text you quote
does not preclude the assignment of 5 to x happening after the
assignment of 11 to x.


Right, I was speaking abstractly. The compiler is still bound by the
semantics of the abstract machine defined by the Standard, it can
perform any optimizations it likes but still must behave "as if" the
the semantics of the abstract machine were honored. In this case that
could mean reducing the expression to x = 11 (given no volatile
qualifier for x) but it cannot introduce undefined behavior in the
process. My point is that following the semantics outlined in the
Standard requires evaluating the RHS first and that any optimizations
must behave "as if" this were actually done.

Robert Gamble

May 27 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
10906
by: Scott Beavers | last post by:
I'm trying to create a form in Excel to sort from the form and take the data to another worksheet. I am very new to this and any help would be appreciated. I have a value in a cell that will direct what sheet I want the cells copied to, so I thought I could use an If statement but have been unable to right the code properly, ie... If "f2" = 1 Then Sheets("XX1").Select
0
3332
by: jason | last post by:
Hello - looking for an efficient way in perl (been a while) to use a control file to pass or fail strings submitted to a perl program. I have a flat file allow.txt in the following format. It does not have to be in this format, it can be in regex format - and maybe should be. f1 -+f2 -+f3 -+f4 -+f6 ... records in the file may look as follows (for example)
5
1551
by: Gianni Mariani | last post by:
The 3 compilers I tried all did different things. gcc 3.4.0 ICE's (Bug 15480) MS C++ 7.1 has meaningless diags Comeau accepts the code Obviously this is not somthing I'll be using until we get the compilers doing the right thing, but I do want to report the appropriate errors. BTW, I think the code is valid. It does the thing I was trying to do
16
5683
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
28
5963
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is uncertain, as such numbers are not represented exactly. See section 4.7 for Rounding issues.
62
12288
jkmyoung
by: jkmyoung | last post by:
Does anyone have some super, super hard Sudoku puzzles? Back in February this year, I had enough time to finally program a Sudoku solver in Java. Right now, I'm looking for solvable puzzles, but ones that my program cannot solve. However, most hard puzzles in the newspapers are solved within 2-3 cycles so far. The ones I've found on google which are said to be hard, get solved in 3 cycles. Any help would be very much appreciated!...
7
2171
by: mandanarchi | last post by:
I found the answer last time I was 'playing' with xsl, but I didn't need to use it then and like an idiot, I didn't save where I found it. I've tried Google but it's not coming up with what I need. From Access I'm exporting a file to xml in the following format: <XMLTemp> <Who>JoeSmith</Who> <Contact>Billy Joe</Contact> <telephone>123457980</telephone> <PostCode>XX1 2XX</PostCode> <When>01/01/2009</When>
0
9997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11279
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10981
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9675
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4725
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.