Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > side effects?

Reply
Thread Tools

side effects?

 
 
Senthil
Guest
Posts: n/a
 
      06-27-2007
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

 
Reply With Quote
 
 
 
 
Nethali
Guest
Posts: n/a
 
      06-27-2007
On Jun 27, 2:14 pm, Senthil <(E-Mail Removed)> 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


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.

 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      06-27-2007
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
 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      06-27-2007
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
 
Reply With Quote
 
=?ISO-8859-1?Q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      06-27-2007
On 2007-06-27 07:46, Nethali wrote:
> On Jun 27, 2:14 pm, Senthil <(E-Mail Removed)> 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

>
> 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
 
Reply With Quote
 
s_amrollahi@yahoo.com
Guest
Posts: n/a
 
      06-27-2007
On Jun 27, 6:14 am, Senthil <(E-Mail Removed)> 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


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

 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      06-28-2007
"Senthil" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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.


 
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
Same network on client side and LAN side of VPN concentrator binand@gmail.com Cisco 1 12-15-2004 05:48 AM
VS.NET 2003 debugging became very slow after installing VS6 side by side Andy Chau ASP .Net 0 11-20-2003 01:19 AM
Framework 1.0 ad 1.1 running side by side configuration problems? Juan Posadas ASP .Net 4 08-26-2003 06:45 AM
<system.diagnostics> error on side-by-side installation... S.K. Dutta ASP .Net 2 07-30-2003 06:55 AM
button evet ---- server side - client side ??? yaya coco ASP .Net 1 07-04-2003 10:58 PM



Advertisments