473,836 Members | 1,503 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 4916
On 2006-05-27, Jordan Abel <ra*******@gmai l.com> wrote:
On 2006-05-27, CBFalconer <cb********@yah oo.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?


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.

--
Andrew Poelstra < http://www.wpsoftware.net/blog >
To email me, use "apoelstra" at the above address.
It's just like stealing teeth from a baby.
May 27 '06 #21
On 2006-05-27, pemo <us***********@ 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?


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(fo o,"hello"),spri ntf(foo," world!\n"));

could do things in this order:

x=8
x=5
set foo to "hello"
set foo to "world!\n"
May 27 '06 #22
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:
>> 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.


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

May 27 '06 #23
On 2006-05-27, Andrew Poelstra <ap*******@loca lhost.localdoma in> wrote:
On 2006-05-27, Jordan Abel <ra*******@gmai l.com> wrote:
On 2006-05-27, CBFalconer <cb********@yah oo.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?

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.
May 27 '06 #24

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?


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.

May 27 '06 #25

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


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

May 27 '06 #26

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.


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

May 27 '06 #27

Jordan Abel wrote:
On 2006-05-27, pemo <us***********@ 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?


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(fo o,"hello"),spri ntf(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.

May 27 '06 #28
Keith Thompson wrote:
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.


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

May 27 '06 #29

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:
>> 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.


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.

May 27 '06 #30

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

Similar topics

9
10903
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
3331
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
5675
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
5943
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
12273
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
2170
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
9816
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
9668
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10840
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
10546
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...
0
10254
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
6978
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5647
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4448
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
3
3112
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.