Re: Newbie-Side effects?

Discussion in 'C Programming' started by Giuseppe, Jun 24, 2003.

  1. Giuseppe

    Giuseppe Guest

    On Wed, 18 Jun 2003, CBFalconer <> wrote:

    >Richard Bos wrote:
    >> (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
    scrive

    >--
    >Chuck F () ()
    > Available for consulting/temporary embedded and systems.
    > <http://cbfalconer.home.att.net> USE worldnet address!
    >
    >
     
    Giuseppe, Jun 24, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Bancroft
    Replies:
    2
    Views:
    2,430
    =?Utf-8?B?UmFodWwgQW5hbmQ=?=
    Dec 28, 2004
  2. Anonieko
    Replies:
    0
    Views:
    1,962
    Anonieko
    Aug 12, 2005
  3. Glen Herrmannsfeldt

    Re: Newbie-Side effects?

    Glen Herrmannsfeldt, Jun 24, 2003, in forum: C Programming
    Replies:
    1
    Views:
    1,337
    CBFalconer
    Jun 24, 2003
  4. Ben Pfaff

    Re: Newbie-Side effects?

    Ben Pfaff, Jun 26, 2003, in forum: C Programming
    Replies:
    0
    Views:
    776
    Ben Pfaff
    Jun 26, 2003
  5. prashna

    Re: Newbie-Side effects?Another rule

    prashna, Jun 27, 2003, in forum: C Programming
    Replies:
    1
    Views:
    987
    Joona I Palaste
    Jun 27, 2003
Loading...

Share This Page