473,902 Members | 4,459 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 4951
On 2006-05-27, en******@yahoo. com <en******@yahoo .com> wrote:

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.


Repeat after me:

Sequence points define a partial ordering.
May 27 '06 #31
On 2006-05-27, en******@yahoo. com <en******@yahoo .com> wrote:

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 "as if" rule applies.

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

--
pete
May 28 '06 #33
On 27 May 2006 13:49:50 -0700,
en******@yahoo. com <en******@yahoo .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?


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.

--
God said, "div D = rho, div B = 0, curl E = - @B/@t, curl H = J + @D/@t,"
and there was light.

http://tjw.hn.org/ http://www.locofungus.btinternet.co.uk/
May 28 '06 #34
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.)

May 28 '06 #35
On 2006-05-27, Jordan Abel <ra*******@gmai l.com> wrote:
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.


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.

--
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 28 '06 #36
Robert Gamble wrote:

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:Th***** ********@gmail. com>

May 28 '06 #37
Kenneth Brody wrote:
Robert Gamble wrote:

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

May 28 '06 #38

Jordan Abel wrote:
On 2006-05-27, en******@yahoo. com <en******@yahoo .com> wrote:

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.


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.

May 28 '06 #39

Tim Woodall wrote:
On 27 May 2006 13:49:50 -0700,
en******@yahoo. com <en******@yahoo .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?


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.


You're welcome to your opinion, but don't expect to convince
anyone without backing it up with language from the Standard.

In fact, the Standard does require that an expression be evaluated
before its value is produced, as I have explained at length in a
previous thread.

May 28 '06 #40

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
10870
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
9673
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
7205
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
5893
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
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
3
3323
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.