Question about sequence points

S

spibou

Consider the expression x = f(...) ;

1. The function f may or may not take arguments.
x is a global variable which is visible to f and any
functions which may be called by f or functions
which appear as arguments to f in the above
expression.

2. The list of arguments to f does not contain any
operators which modify the value of x and also
functions called by f or appearing as arguments to
f do not modify the value of x.

3. f itself may modify the value of x.

Is the above expression well defined ? If you think
it is could you explain how it follows from the standard ?

Personally I feel it is well defined. If there are any disagreements
I will explain my reasoning later.


Spiros Bousbouras
 
E

Eric Sosman

Consider the expression x = f(...) ;

1. The function f may or may not take arguments.
x is a global variable which is visible to f and any
functions which may be called by f or functions
which appear as arguments to f in the above
expression.

2. The list of arguments to f does not contain any
operators which modify the value of x and also
functions called by f or appearing as arguments to
f do not modify the value of x.

3. f itself may modify the value of x.

Is the above expression well defined ? If you think
it is could you explain how it follows from the standard ?

Personally I feel it is well defined. If there are any disagreements
I will explain my reasoning later.

Well-defined. There is a sequence point after the
arguments are evaluated, before the body of f() begins
executing. If f() is written in C, there is another
sequence point at the end of each of its statements; in
particular, there is a sequence point at the end of the
`return somevalue;' statement. (If f() is not written
in C, all bets are off: The C Standard does not govern
what other languages do.)
 
C

Clark S. Cox III

Consider the expression x = f(...) ;

1. The function f may or may not take arguments.
x is a global variable which is visible to f and any
functions which may be called by f or functions
which appear as arguments to f in the above
expression.

2. The list of arguments to f does not contain any
operators which modify the value of x and also
functions called by f or appearing as arguments to
f do not modify the value of x.

3. f itself may modify the value of x.

Is the above expression well defined ? If you think
it is could you explain how it follows from the standard ?

Personally I feel it is well defined. If there are any disagreements
I will explain my reasoning later.

Why wouldn't it be well defined?

int x;

int f(int,int,int)
{
return x++;//There is a sequence point at the end of this expression
}

int main()
{
x = f(1,2,3); //There is a sequence point at the call itself

//x == 0 at this point


return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top