Re: Newbie-Side effects?Another rule

Discussion in 'C Programming' started by prashna, Jun 27, 2003.

  1. prashna

    prashna Guest

    (prashna) wrote in message news:<>...
    > 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.
    prashna, Jun 27, 2003
    #1
    1. Advertising

  2. prashna <> scribbled the following:
    > (prashna) wrote in message news:<>...
    >> 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 () ---------------------------\
    | 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
    Joona I Palaste, Jun 27, 2003
    #2
    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,387
    =?Utf-8?B?UmFodWwgQW5hbmQ=?=
    Dec 28, 2004
  2. Giuseppe

    Re: Newbie-Side effects?

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

    Re: Newbie-Side effects?

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

    Re: Newbie-Side effects?

    Ben Pfaff, Jun 26, 2003, in forum: C Programming
    Replies:
    0
    Views:
    762
    Ben Pfaff
    Jun 26, 2003
  5. Replies:
    0
    Views:
    1,356
Loading...

Share This Page