Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   C++ side effects (http://www.velocityreviews.com/forums/t609901-c-side-effects.html)

baibaichen 04-08-2008 10:42 AM

C++ side effects
 
hi All

the following comes from c++ standards:

"Accessing an object designated by a volatile lvalue (3.10), modifying
an object, calling a library I/O
function, or calling a function that does any of those operations are
all side effects, which are changes in the
state of the execution environment."

According to this definition, consider this function,

T ReturnT(){
T result_;
//do something
return result_; // #1
}

At #1, I think
1) if T is scalre type such as int or char, the returning sentence
would not have side effects
2) if T is a class type, does returning type T have side effects? and
Why? I.e. which program state is changed in the T's copy constrcutor.

Thanks
Chang

Abhishek Padmanabh 04-08-2008 03:16 PM

Re: C++ side effects
 
On Apr 8, 3:42*pm, baibaichen <baibaic...@gmail.com> wrote:
> the following comes from c++ standards:
>
> "Accessing an object designated by a volatile lvalue (3.10), modifying
> an object, calling a library I/O
> function, or calling a function that does any of those operations are
> all side effects, which are changes in the
> state of the execution environment."
>
> According to this definition, consider this function,
>
> T ReturnT(){
> * * T result_;
> * * //do something
> * *return result_; * *// #1
>
> }
>
> At #1, I think
> 1) if T is scalre type such as int or char, the returning sentence
> would not have side effects
> 2) if T is a class type, *does returning type T have side effects? and
> Why? I.e. which program state is changed in the T's copy constrcutor.


Could be anything depending upon what's written in the copy
constructor for the specific type T. No? For example, even a simple
print to console or writing something to a log file (both I/O related)
could be considered a side-effect. Copies as in above can be elided
via RVO/NRVO alongwith those side-effects.


All times are GMT. The time now is 02:26 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57