Re: Newbie-Side effects?

Discussion in 'C Programming' started by Ben Pfaff, Jun 26, 2003.

  1. Ben Pfaff

    Ben Pfaff Guest

    (Richard Bos) writes:

    > (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)
    y++;
    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
    Ben Pfaff, Jun 26, 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,388
    =?Utf-8?B?UmFodWwgQW5hbmQ=?=
    Dec 28, 2004
  2. Anonieko
    Replies:
    0
    Views:
    1,940
    Anonieko
    Aug 12, 2005
  3. Giuseppe

    Re: Newbie-Side effects?

    Giuseppe, Jun 24, 2003, in forum: C Programming
    Replies:
    0
    Views:
    1,158
    Giuseppe
    Jun 24, 2003
  4. Glen Herrmannsfeldt

    Re: Newbie-Side effects?

    Glen Herrmannsfeldt, Jun 24, 2003, in forum: C Programming
    Replies:
    1
    Views:
    1,321
    CBFalconer
    Jun 24, 2003
  5. prashna

    Re: Newbie-Side effects?Another rule

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

Share This Page