Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Re: Newbie-Side effects?Another rule (http://www.velocityreviews.com/forums/t313860-re-newbie-side-effects-another-rule.html)

prashna 06-27-2003 08:24 AM

Re: Newbie-Side effects?Another rule
 
vashwath@rediffmail.com (prashna) wrote in message news:<d40d7104.0306172222.59de0478@posting.google. com>...
> Hi all,
> I am new to C and I am in a code review project( the review has to
> be done with respect to some predefined rules)and I came across rule
> which states "The right hand operand of a && or || operator shall not
> contain side effects.".Please let me know what are these side effects?


There is another rule which is also quite confusing,here is what it
say's,
"Non-null statements shall have a side-effect."!!!!Now what does this
mean?Does it mean that every statement should change state of some
variable.for example if there is a statement which prints "Hello
world" [like printf("Hello world\n");]on the std output then, since
this statement is not changing any variable it is violating this rule.

Thanks in advance.

Joona I Palaste 06-27-2003 08:31 AM

Re: Newbie-Side effects?Another rule
 
prashna <vashwath@rediffmail.com> scribbled the following:
> vashwath@rediffmail.com (prashna) wrote in message news:<d40d7104.0306172222.59de0478@posting.google. com>...
>> Hi all,
>> I am new to C and I am in a code review project( the review has to
>> be done with respect to some predefined rules)and I came across rule
>> which states "The right hand operand of a && or || operator shall not
>> contain side effects.".Please let me know what are these side effects?


> There is another rule which is also quite confusing,here is what it
> say's,
> "Non-null statements shall have a side-effect."!!!!Now what does this
> mean?Does it mean that every statement should change state of some
> variable.for example if there is a statement which prints "Hello
> world" [like printf("Hello world\n");]on the std output then, since
> this statement is not changing any variable it is violating this rule.


No, I believe you have misunderstood something here. The statement:
printf("Hello world\n");
*does* have a side effect. Side effects are not limited to changing the
state of a variable. A side effect is *anything* that changes the state
of *anything* outside any temporary evaluation storage. Here the state
change is printing "Hello world\n" to stdout. The state of the data
contained in the stdout stream changes.
What the rule is preventing is statements like:
"Hello world\n";
printf; /* note: not printf(); */
which don't have side effects. In fact, in Java, statements without
side effects are forbidden (get this!) *AT THE LANGUAGE LEVEL!* I can't
understand why that language has to be so picky.

--
/-- Joona Palaste (palaste@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Shh! The maestro is decomposing!"
- Gary Larson


All times are GMT. The time now is 06:29 PM.

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