Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > define side effects

Reply
Thread Tools

define side effects

 
 
Niklaus
Guest
Posts: n/a
 
      05-05-2004
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. I am really confused. Can some one give me a
more clear definition of side effects ?

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 ? Can
someone throw more light on how to define side effects without
ambiguity ?

-
Nik
 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      05-05-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (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.

Richard
 
Reply With Quote
 
 
 
 
Gautam
Guest
Posts: n/a
 
      05-05-2004
(E-Mail Removed) (Richard Bos) wrote in message news:<(E-Mail Removed)>...
> (E-Mail Removed) (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.
>
> Richard



regarding side - effects
what exactly does this sequence 'point mean'
 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      05-05-2004
Gautam <(E-Mail Removed)> scribbled the following:
> (E-Mail Removed) (Richard Bos) wrote in message news:<(E-Mail Removed)>...
>> (E-Mail Removed) (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 ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"You could take his life and..."
- Mirja Tolsa
 
Reply With Quote
 
Neil Kurzman
Guest
Posts: n/a
 
      05-08-2004
Simply

The same as in medicine. A drug cures one problem, but causes another.

In code you fix one bug, but cause another.

 
Reply With Quote
 
Arthur J. O'Dwyer
Guest
Posts: n/a
 
      05-08-2004

On Sat, 8 May 2004, Neil Kurzman wrote only:
>
> Simply
> The same as in medicine. A drug cures one problem, but causes another.
> In code you fix one bug, but cause another.


An interesting quotation, but why do you say so? If this is
supposed to be a new topic of discussion (incidentally, one more
suited to comp.programming than comp.lang.c, which is dedicated
specifically to fixing bugs in *C* code then you might have
considered starting a new thread rather than piggybacking on an
existing one.
We've seen people here before who apparently thought they should
"conserve threads" by posting irrelevant replies to old threads;
that's really not necessary.
And if you *didn't* mean your reply to be irrelevant to the old
thread, then you ought to have quoted some context so people could
tell to what you were responding. Google "usenet faq" for more
information.

-Arthur
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Url Rewriting with just an HttpHandler (without the side-effects) Anonieko ASP .Net 0 08-12-2005 01:10 AM
Calling DataBind() multiple times-- strange side effects? Jim Bancroft ASP .Net 2 12-28-2004 12:57 PM
Evaluating expressions with side effects. Jason Heyes C++ 10 12-21-2004 05:17 PM
Object reference side effects - desirable? VisionSet Java 7 11-09-2004 02:09 AM



Advertisments