473,899 Members | 4,557 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 4949
Old Wolf wrote:
Tim Woodall wrote:
On 29 May 2006 06:32:10 -0700,
en******@yahoo. com <en******@yahoo .com> wrote:

Of course not. The order of evaluation of the operators
doesn't determine the order in which the side effects
take place. Evaluating an assignment operator causes
a store to take place, but the side effect of updating the
stored value may take place at any point before the
next sequence point (and after the assignment operator
has been evaluated).


Now we're getting somewhere.

"(and after the assignment operator has been evaluated)"

Where is this in the standard?


It isn't. A side-effect is part of an expression evaluation.
It may occur before or after (or at the same time as) the
value of the expression is computed.

(The point I'm making else-thread is that the side-effect
"obviously" cannot occur before the right-hand operand
has been evaluated.)
(a,b) + (c,d)

if an example implementation evaluates a then b then c then d then you
seem to be saying that the sequence point after c but before d means
that all the side effects of evaluating b will have completed.


I don't see where he is saying that.
This I disagree with.


Naturally. a's side effects must complete before b is evaluated,
and c's side effects must complete before d is evaluated; there
is no other constraint.


Even though with the given ordering, the next sequence point after the
evaluation of b is that of the comma operator separating c and d ?

If that's how you feel, then I don't see how you can claim the
evaluation of the outer = operator in x=(x=5,11) can't start before the
operands have been fully evaluated. "Obviously" doesn't apply, since a
possible way has been given in other messages already.

May 29 '06 #81
Harald van Dijk wrote:
Old Wolf wrote:
Tim Woodall wrote:
(a,b) + (c,d)
a's side effects must complete before b is evaluated,
and c's side effects must complete before d is evaluated; there
is no other constraint.


Even though with the given ordering, the next sequence point after the
evaluation of b is that of the comma operator separating c and d ?


The sequence points could occur in either order, because the
order of evaluation of the operands of (+) is unspecified.
If that's how you feel, then I don't see how you can claim the
evaluation of the outer = operator in x=(x=5,11) can't start beforethe
operands have been fully evaluated.


I'm claiming that the side-effect of the outer = cannot occur
until the operands have been fully evaluated (with side-effects
of those evaluations not necessarily complete).

May 30 '06 #82
Old Wolf wrote:
Harald van Dijk wrote:
Old Wolf wrote:
Tim Woodall wrote:

(a,b) + (c,d)

a's side effects must complete before b is evaluated,
and c's side effects must complete before d is evaluated; there
is no other constraint.


Even though with the given ordering, the next sequence point after the
evaluation of b is that of the comma operator separating c and d ?


The sequence points could occur in either order, because the
order of evaluation of the operands of (+) is unspecified.


You snipped the relevant sentence:

"if an example implementation evaluates a then b then c then d then you
seem to be saying that the sequence point after c but before d means
that all the side effects of evaluating b will have completed."

This evaluation order is not at all required, but *IF* this is the one
that's used, does your view change any?

May 30 '06 #83

Tim Woodall wrote:
On 29 May 2006 06:32:10 -0700,
en******@yahoo. com <en******@yahoo .com> wrote:

Of course not. The order of evaluation of the operators
doesn't determine the order in which the side effects
take place. Evaluating an assignment operator causes
a store to take place, but the side effect of updating the
stored value may take place at any point before the
next sequence point (and after the assignment operator
has been evaluated).

Now we're getting somewhere.

"(and after the assignment operator has been evaluated)"

Where is this in the standard?


"Evaluation of an expression may produce side effects."
Obviously if evaluation produces the side effects, then
the side effects can't come first.
(a,b) + (c,d)

if an example implementation evaluates a then b then c then d then you
seem to be saying that the sequence point after c but before d means
that all the side effects of evaluating b will have completed.


I'm not. Both commas must be evaluated before plus. There is
no ordering between either operand of the first comma and
either operand of the second comma. When the Standard says
"the next sequence point" what it means is the first sequence
point that must come afterwards in all possible orderings. The
next sequence point after b is the sequence point of the whole
expression, regardless of evaluation order.

May 30 '06 #84

en******@yahoo. com wrote:
Tim Woodall wrote:
On 29 May 2006 06:32:10 -0700,
en******@yahoo. com <en******@yahoo .com> wrote:

Of course not. The order of evaluation of the operators
doesn't determine the order in which the side effects
take place. Evaluating an assignment operator causes
a store to take place, but the side effect of updating the
stored value may take place at any point before the
next sequence point (and after the assignment operator
has been evaluated).

Now we're getting somewhere.

"(and after the assignment operator has been evaluated)"

Where is this in the standard?


"Evaluation of an expression may produce side effects."
Obviously if evaluation produces the side effects, then
the side effects can't come first.


But they can come during.
(a,b) + (c,d)

if an example implementation evaluates a then b then c then d then you
seem to be saying that the sequence point after c but before d means
that all the side effects of evaluating b will have completed.


I'm not. Both commas must be evaluated before plus. There is
no ordering between either operand of the first comma and
either operand of the second comma. When the Standard says
"the next sequence point" what it means is the first sequence
point that must come afterwards in all possible orderings. The
next sequence point after b is the sequence point of the whole
expression, regardless of evaluation order.


So does this have undefined behaviour, or implementation defined
behaviour?

#include <stdio.h>

int* f(int x)
{
static int d[4];
static int done[4];
static int twice;
done[x]=1;
if(x==2 && done[0] && done[1])
twice=1;
if(x==3 && twice)
return &d[1];
else
return &d[x];
}

int main(void)
{
printf("%d\n", ( (*f(0))++, (*f(1))++ ) + ( (*f(2))++, (*f(3))++ )
);
return 0;
}
FYI:
$ gcc -W -Wall -ansi -pedantic -O2 -o test test.c
$ ./test
1
$

Despite gcc doing a then b then c then d, I'm saying that this is
undefined behaviour because the sequence point at the second comma does
not limit when the side effects of b can occur and so can overlap with
the side effects of d.

Tim.

May 30 '06 #85
Harald van Dijk wrote:
>> (a,b) + (c,d)
You snipped the relevant sentence:


Sorry -- I misread
"if an example implementation evaluates a then b then c then d then you
seem to be saying that the sequence point after c but before d means
that all the side effects of evaluating b will have completed."
Yes: if b is evaluated before c, then b's side effect must complete
before d is evaluated.
This evaluation order is not at all required, but *IF* this is the one
that's used, does your view change any?


No. This doesn't exclude the possibility:
- evaluate a
- evaluate c
- evaluate d
- evaluate b
- b's side effect
- d's side effect

May 31 '06 #86
On 29 May 2006 07:14:23 -0700, go****@woodall. me.uk wrote:
<snip>
Incidentally, there is, I think, an appendix "Formal model of sequence
points" http://www.davros.org/c/wg14n822.txt
(http://www.davros.org/c/wg14papers.html - informative, not normative)
which I _think_ would agree that x=(x=5,11); is defined.

Several versions of a formal model were attempted during the C99
process, but apparently none of them got enough support to be adopted.

- David.Thompson1 at worldnet.att.ne t
Jun 8 '06 #87

go****@woodall. me.uk wrote:
en******@yahoo. com wrote:
Tim Woodall wrote:
On 29 May 2006 06:32:10 -0700,
en******@yahoo. com <en******@yahoo .com> wrote:
>
> Of course not. The order of evaluation of the operators
> doesn't determine the order in which the side effects
> take place. Evaluating an assignment operator causes
> a store to take place, but the side effect of updating the
> stored value may take place at any point before the
> next sequence point (and after the assignment operator
> has been evaluated).
>

Now we're getting somewhere.

"(and after the assignment operator has been evaluated)"

Where is this in the standard?
"Evaluation of an expression may produce side effects."
Obviously if evaluation produces the side effects, then
the side effects can't come first.


But they can come during.


Evaluation of operators are point events. See Wojtek's
explanation in comp.std.c.
(a,b) + (c,d)

if an example implementation evaluates a then b then c then d then you
seem to be saying that the sequence point after c but before d means
that all the side effects of evaluating b will have completed.


I'm not. Both commas must be evaluated before plus. There is
no ordering between either operand of the first comma and
either operand of the second comma. When the Standard says
"the next sequence point" what it means is the first sequence
point that must come afterwards in all possible orderings. The
next sequence point after b is the sequence point of the whole
expression, regardless of evaluation order.


So does this have undefined behaviour, or implementation defined
behaviour?

#include <stdio.h>

int* f(int x)
{
static int d[4];
static int done[4];
static int twice;
done[x]=1;
if(x==2 && done[0] && done[1])
twice=1;
if(x==3 && twice)
return &d[1];
else
return &d[x];
}

int main(void)
{
printf("%d\n", ( (*f(0))++, (*f(1))++ ) + ( (*f(2))++, (*f(3))++ )
);
return 0;
}


Undefined behavior.
FYI:
$ gcc -W -Wall -ansi -pedantic -O2 -o test test.c
$ ./test
1
$

Despite gcc doing a then b then c then d, I'm saying that this is
undefined behaviour because the sequence point at the second comma does
not limit when the side effects of b can occur and so can overlap with
the side effects of d.


Correct.

Jun 19 '06 #88

Old Wolf wrote:
Harald van Dijk wrote:
>>> (a,b) + (c,d)

You snipped the relevant sentence:


Sorry -- I misread
"if an example implementation evaluates a then b then c then d then you
seem to be saying that the sequence point after c but before d means
that all the side effects of evaluating b will have completed."


Yes: if b is evaluated before c, then b's side effect must complete
before d is evaluated.


Sorry, that isn't right. The terms "previous sequence point"
and "next sequence point" are to be read as a logical relationship
based on the abstract syntax tree, not a temporal relationship
based on any particular execution order.

Jun 19 '06 #89
en******@yahoo. com wrote:
Old Wolf wrote:
Harald van Dijk wrote:
> >>> (a,b) + (c,d)
You snipped the relevant sentence:


Sorry -- I misread
"if an example implementation evaluates a then b then c then d then you
seem to be saying that the sequence point after c but before d means
that all the side effects of evaluating b will have completed."


Yes: if b is evaluated before c, then b's side effect must complete
before d is evaluated.


Sorry, that isn't right. The terms "previous sequence point"
and "next sequence point" are to be read as a logical relationship
based on the abstract syntax tree, not a temporal relationship
based on any particular execution order.


So you keep asserting, even though it is clear there is disagreement
and the standard is unclear about it.

Jun 19 '06 #90

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
9843
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
10863
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
10971
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
10494
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
9666
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 projectplanning, coding, testing, and deploymentwithout 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...
0
7201
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
5887
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...
0
6081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4720
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.