Re: define side effects

From: Joona I Palaste (palaste_at_cc.helsinki.fi)
Date: 05/05/04


Date: 5 May 2004 16:52:37 GMT

Gautam <gautam92in@yahoo.com> scribbled the following:
> rlb@hoekstra-uitgeverij.nl (Richard Bos) wrote in message news:<4098c06c.80452765@news.individual.net>...
>> niklaus@gamebox.net (Niklaus) wrote:
>>
>> > This is one of the posts that i got.
>> > ------------------------------
>> > A "side effect" of an operation is something that
>> > *happens*, not something that *is produced*. Examples:
>> > In the expression 2+2, the value 4 *is produced*. Nothing
>> > *happens*.
>> > Thus, 4 is the value of the expression, and it has no side effects.
>> > In the expression g=2.0, the value 2.0 is produced. What *happens*
>> > is that 2.0 is assigned to g. Thus, 2.0 is the value of the
>> > expression,
>> > and its side effect is to assign 2.0 to g.
>> > In the expression (int)g, the value 2 is produced. Nothing happens.
>> > Thus, 2 is the value of the expression (int)g, and it has no side
>> > effects.
>> > In the expression (a=1,++a), the value 2 is produced. What happens
>> > is that first 1 is assigned to a, and then a is incremented; those are
>> > the side effects of the expression.
>> > -----------------------------
>> >
>> > This seems to be a good definition in most of the cases.
>> >
>> > I argue that in k=(int)2.0 , 2 is produced and the truncation of 2.0
>> > -> 2 is that happens.
>>
>> No; the 2.0 is not changed. Nothing happens "behind the scenes"; the
>> value 2.0 does get truncated, but only for the direct reason of
>> calculating the value of the expression. Assigning this truncated value
>> to k _is_ a side effect.
>>
>> > I am really confused. Can some one give me a more clear definition
>> > of side effects ?
>>
>> Well, according to the Standard,
>>
>> # [#2] Accessing a volatile object, modifying an object,
>> # modifying a file, or calling a function that does any of
>> # those operations are all side effects, which are changes
>> # in the state of the execution environment.
>>
>> Whether that is more clear, well... it's unambiguous, anyway.
>>
>> > If i apply the same definition to i=j++ where j=3 then i=3 and j=4
>> > are the side effects and value 3,4 are produced. Am i correct ?
>>
>> No; 4 is never produced. j is increased to 4, but that value is never
>> passed on to any other sub-expression; its previous value, 3, is.

> regarding side - effects
> what exactly does this sequence 'point mean'

It's a point during the evaluation of an expression, when all side
effects are guaranteed to have taken place. Sequence points include:
- The terminating ; in a statement
- The && and || operators
- The ?: operator
- The , operator
Also, AFAIK when a function is called, its entry point forms a
sequence point for the expressions in its arguments.

-- 
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"You could take his life and..."
   - Mirja Tolsa


Relevant Pages

  • Re: GENERATING AUTOMATIC NUMBERS
    ... not, say, it the DefaultValue property of the table field. ... impediment to calculating it at that point is that you first need to know ... in order to look up the current maximum sequence number. ... >>> Date-auto increment format. ...
    (microsoft.public.access.formscoding)
  • Re: GENERATING AUTOMATIC NUMBERS
    ... Graham Mandeno ... "JAMES FENNEL" wrote in message ... in order to look up the current maximum sequence number. ... >> calculating the sequence number and saving the record will increase the ...
    (microsoft.public.access.formscoding)
  • Re: Increment/decrement question
    ... assigning it's value to n2. ... Nit-pick time: ... the increment took place. ... They do take place in the sequence he said. ...
    (comp.lang.c)
  • Re: GENERATING AUTOMATIC NUMBERS
    ... "missing operator" error with the "RecordDate=" part of the statement. ... > impediment to calculating it at that point is that you first need to know ... in order to look up the current maximum sequence number. ... I've tried placing it as a calculated field in a Query and it's ...
    (microsoft.public.access.formscoding)
  • Re: possibly undefined behavior
    ... int main ... It would be UB if there were not a sequence point involved in the ... current value of x and assigning a new value, ... preventing the assignment to x to occur before the function call and ...
    (comp.lang.c)

Loading