Re: operator precedence in c - clarifications needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pete

    Re: operator precedence in c - clarifications needed

    Richard Heathfield wrote:
    CBFalconer said:
    >
    >Prasad wrote:
    >>I am quite familiar with C and have coded a lot. But I get stumped
    >>on precedence rules, and I use paranthesis always. Can one of you
    >>out there explain how the value of s is evaluated in the following
    >>code snippet?
    >>>
    >>int a=5,s=0;
    >>s=(++a) + (a++) + (--a) + (a--);
    >That's an illegal statement.
    >
    No, it isn't. Its behaviour is undefined, but it's not against the law.
    Compilers aren't even obliged to diagnose it.
    Neither are they obliged to compile it.

    Running software that can translate and execute a C program,
    is what an implementation of C is.

    Whether or not running software
    can translate and execute a text file
    containing the line identified by CBFalconer as "illegal",
    has no bearing on whether or not
    that running software is a C implementation.

    Code that contains that line, isn't a C program,
    it's just gibberish that looks like a C program;
    and if your compiler does compile it,
    then you have fooled your compiler.

    Followup-To:comp.lang.c

    --
    pete
Working...