473,386 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

define side effects

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
Nov 14 '05 #1
5 3193
ni*****@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.

Richard
Nov 14 '05 #2
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote in message news:<40***************@news.individual.net>...
ni*****@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.

Richard

regarding side - effects
what exactly does this sequence 'point mean'
Nov 14 '05 #3
Gautam <ga********@yahoo.com> scribbled the following:
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote in message news:<40***************@news.individual.net>...
ni*****@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 (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"You could take his life and..."
- Mirja Tolsa
Nov 14 '05 #4
Simply

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

In code you fix one bug, but cause another.

Nov 14 '05 #5

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
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: johny smith | last post by:
I have never really understood the difference between 1.) #define NUMBER 1.653 vs. 2.) const double NUMBER = 1.653 I know that the #define is taken care of by the pre-processor and the...
23
by: Mantorok Redgormor | last post by:
Can emulation of the logical OR be done in standard C to obfuscate its use? So I don't have to use if(a||b) but instead make that even more obfuscated without its use but testing the same condition
9
by: Rouben Rostamian | last post by:
Consider the following illustrative program: #include <stdio.h> double f(double x) { return x*x; } double g(double x)
13
by: Mantorok Redgormor | last post by:
does volatile really inhibit side effects? that is the rules for sequence points and side effects do not apply to volatile objects? -- nethlek
15
by: Jorge Naxus | last post by:
Hello I would like to write a macro like that: #ifdef DEBUG #define printj(...) printf(...) #else #printj(...) #endif
7
by: Meenu | last post by:
the value of a is 11, how?? #define SQR(x) (x*x) int main() { int a,b=3; a=SQR(b+2); printf("a=%d\n",a); return 0; }
4
by: Marcelo | last post by:
Dear all, I am a beginner of C/C++ programmation and I don't understand how the #define command works. I would like to make this statement #define MAX2(V1, V2) (V1>V2 ? V1 : V2) as a C...
6
by: Senthil | last post by:
Hi, Whenever i read a C++ book or a newsgroup posting, i come across the terms like " before the side effects completes" , "destructor with side effects" etc. What is this side effect mean in C++...
4
by: Academia | last post by:
I get the following watch message: tsSource.Text.ToUpper() This expression causes side effects and will not be evaluated string The Text is &Edit
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.