Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Newbie-Side effects?

Thread Tools

Re: Newbie-Side effects?

Ben Pfaff
Posts: n/a
      06-26-2003 Removed) (Richard Bos) writes:

> (E-Mail Removed) (prashna) wrote:
> > 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?

> Joona has already explained what a side effect is; let me add a remark
> about this rule.
> It stinks.
> It stinks to high heaven, because it makes some useful constructs
> impossible for, AFAICT, no good reason at all. For example, it would
> disallow this line:
> while (--lim>0 && (c=getchar())!=EOF && c!='\n')
> s[i++]=c;

Interestingly, it would also disallow
while (x-- > 0 && getchar() != EOF)
because getchar() has side effects of its own regardless of what
is done with the return value.
"I am worth much more brick-bat!!"
--Uday Joshi
Reply With Quote

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