473,396 Members | 1,789 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,396 software developers and data experts.

side effects?

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++ world?
Is it like something that is not desired but happens automatically and
we cannot prevent it?

Would be great if someone throws light on this.

Thanks,
Senthil

Jun 27 '07 #1
6 4899
On Jun 27, 2:14 pm, Senthil <s.senthil...@gmail.comwrote:
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++ world?
Is it like something that is not desired but happens automatically and
we cannot prevent it?

Would be great if someone throws light on this.

Thanks,
Senthil
All operators produce a value from their operands. This value is
produced without modifying the operands, except with the assignment,
increment, and decrement operators. Modifying an operand is called a
side effect. The most common use for operators that modify their
operands is to generate the side effect, but you should keep in mind
that the value produced is available for your use just as in operators
without side effects.

Jun 27 '07 #2
John Harrison wrote:
Senthil wrote:
>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++ world?
Is it like something that is not desired but happens automatically and
we cannot prevent it?

Would be great if someone throws light on this.

Thanks,
Senthil

It's not a C++ term, it applies to more or less any programming language.

The first paragraph of this
http://en.wikipedia.org/wiki/Side_ef...mputer_science) is a
reasonable definiton.

john
In C++ I guess you would exclude from the definition methods which
modify the state of the 'this' object, since this is an anticipated
feature of OO programming.

john
Jun 27 '07 #3
Senthil wrote:
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++ world?
Is it like something that is not desired but happens automatically and
we cannot prevent it?

Would be great if someone throws light on this.

Thanks,
Senthil
It's not a C++ term, it applies to more or less any programming language.

The first paragraph of this
http://en.wikipedia.org/wiki/Side_ef...mputer_science) is a
reasonable definiton.

john
Jun 27 '07 #4
On Jun 27, 6:14 am, Senthil <s.senthil...@gmail.comwrote:
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++ world?
Is it like something that is not desired but happens automatically and
we cannot prevent it?

Would be great if someone throws light on this.

Thanks,
Senthil
Hi Senthil,
side effect is a term used in programming language in general. For
example see the classic book
Programming Languages by Terence W. Pratt.
In C++ operators usually have side effects, Of course side effect is
not bad things actually sometimes they are needed. For example the
statement
cout << "Hello, world!";
has one operator (<<) and two operands: cout and "Hello, world!". It
means put to "Hello, world" string into cout object. As its side
effect the greeting message will be showed on screen. Indeed in a
typical hello, world program, the side effect do the main task of the
program.

Regards,
S. Amrollahi

Jun 27 '07 #5
On 2007-06-27 07:46, Nethali wrote:
On Jun 27, 2:14 pm, Senthil <s.senthil...@gmail.comwrote:
>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++ world?
Is it like something that is not desired but happens automatically and
we cannot prevent it?

Would be great if someone throws light on this.

Thanks,
Senthil

All operators produce a value from their operands. This value is
produced without modifying the operands, except with the assignment,
increment, and decrement operators. Modifying an operand is called a
side effect. The most common use for operators that modify their
operands is to generate the side effect, but you should keep in mind
that the value produced is available for your use just as in operators
without side effects.
It should be noted though that side effects can be much more than just
modifications of the operands, it can also involve modifications of
other objects, global data, I/O operations etc. Basically, anything that
makes a changes beside the return-value is a side effect.

--
Erik Wikström
Jun 27 '07 #6
"Senthil" <s.**********@gmail.comwrote in message
news:11*********************@z28g2000prd.googlegro ups.com...
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++ world?
Is it like something that is not desired but happens automatically and
we cannot prevent it?

Would be great if someone throws light on this.
Consider a simple side effect, someone writes a class and wants to keep
track/debug constructors, destructors and such and so in each does std::cout
<< "Class X Constructor", std::cout << "Class X Destructor", std::cout <<
"Class X Copy Constructor", etc...

Those are side effects (the outputs). Compilers may be free to not do a
copy constructor when one would normally be done if it can do it more
effeciently some other way. For example, say there is an instruciton that
would normally create a temporary object using a constructor then use a copy
constructor to create an object (or assignment operator). The compiler may
just deside to create the object directory from the constructor doing away
with the copy or assignments. Normally, that's fine, but in this case we
don't see the side effects, the output of "Class X Copy Constructor", etc...

It is a little more detailed than that, that is a simplistic description
because I really don't know all what exactly makes up a side effect. I do
know that it is often refered to in if statments:

if ( A || B )

B may not always be evaluated (if A is true then the if statment is
short-circuited, only A is evaluated) and so if B has side effects you may
expect to see them but may not. Consider a simplistic case: (untested code)

class Foo
{
public:
Foo( bool Enable ): Enabled_( Enable ) {}
bool Enabled() { std::cout << "Checking if enabled...\n'; return
Enabled_; }
private:
bool Enabled_;
}

int main()
{
bool Bar = true;
Foo Foobar( false );

if ( Bar || Foo.Enabled() }
std::cout << "One is true...\n";
}

At first glance, one may expect the output of this program to be:
Checking if enabled...
One is true...

But the output will most likely be:
One is true...

Because of short circuiting, Foo.Enabled() is not evaluated and it's "side
effects" are not performed.
Jun 28 '07 #7

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

Similar topics

3
by: Sensorflo | last post by:
After browsing though many newsgroups articels I'm still not shure how operator precedence, operator associativity, sequence points, side effects go together. Currently I have the following view: ...
13
by: Steve Jorgensen | last post by:
== On Error Resume next, and Err.Number == If you want to call one of your procedures from another procedure, and check for errors afterward, you mayimagine that you should write code something...
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
5
by: Niklaus | last post by:
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...
17
by: dingoatemydonut | last post by:
The C99 standard states: "In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce...
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
10
by: mirandacascade | last post by:
Question toward the bottom of this post....background information immediately below. Access 97 SQL Server 2000 Please note: although the subject line uses the word 'bloat', this post is NOT...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...
0
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...
0
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 project—planning, coding, testing,...

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.