in reply to Perl vs C

Dear Santhosh_89

Have a look on this they have discussed increment operator precedence between C and Perl

Difference

Replies are listed 'Best First'.
Re^2: Perl vs C
by GrandFather (Saint) on Mar 14, 2009 at 06:01 UTC

    Actually if you read that thread you will discover that it discusses a single issue and that the issue is one of specific compiler/interpreter implementation unrelated related to language differences.


    True laziness is hard work
Re^2: Perl vs C
by Marshall (Canon) on Mar 14, 2009 at 15:15 UTC
    I looked at this other post. re: C
    k = i++ + i++;
    That is "weird looking". I recommend a more clear statement of intent!
    x = i++; /*maybe*/
    k = x + x; /*maybe ???? */
    I am not sure what the precedence rules are with 3 +++ in row. I recommend that you use a couple of statements to make this more clear.

    BTW: In Perl, sub x (--$i, $i++) behavior is also undefined.
    The order of operands to a sub can be evaluated in any order. This is true in C also.

      In Perl, sub x (--$i, $i++) behavior is also undefined

      Not really. On all platforms, operands are always evaluated from left to right except for assignment operators, where it's right to left. People regularly rely on this.

      sub foo { shift->bar('foo', @_)) }
      { my $x = $x; ... }

      The latter is even documented.

      The problem is that it gets really tricky when lvalues are involved.

      f($i, --$i, $i);
      The first argument is evaluated first, but it's still affected by the decrement because Perl passes by reference.
        I think we both might be right on this question. There is one issue of lvalue calculation in a single statement. Then there is the issue of what happens in a sub call with say foo (++I, --I). In C, we don't know whether "I" will get incremented or decremented first. This is like when you go to the doctor and you say, "it hurts when I press here", and he says, "don't do that".

        The fact that we are "arguing" about some syntax says to me that the syntax isn't clear enough. I am not gonna argue precedence.. Hey, that there is even a question at this level means it the code was not clear enough to begin with!

        Think about what will happen say 2 years from now? My opinion is that clear code is good code.