Velocity Reviews - Computer Hardware Reviews

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

Thread Tools

Re: Newbie-Side effects?

Posts: n/a
On Wed, 18 Jun 2003, CBFalconer <(E-Mail Removed)> wrote:

>Richard Bos wrote:
>> 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;
>> Of course, you could always rewrite this as
>> while (--lim>0) {
>> if ((c=getchar())!=EOF && c!='\n') break;
>> s[i++]=c;
>> }
>> but I see no reason why the original would be deemed inferior.

>If you have to worry about code being maintained by people with
>less C knowledge than you, it makes perfect sense. Of course the
>rules should include the use of blanks around symbols also
>For consistency you should have written your line as:
> while(--lim>0&&(c=getchar())!=EOF&&c!='\n')s[i++]=c;
>I found at least 8 wasted blanks and a wasted line

Non capire (quello che dannoso) dipende da chi legge e non da chi

>Chuck F ((E-Mail Removed)) ((E-Mail Removed))
> Available for consulting/temporary embedded and systems.
> <> USE worldnet address!

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