![]() |
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 |
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.