• nybble41@programming.dev
    link
    fedilink
    arrow-up
    3
    ·
    1 year ago

    I’m fairly certain that last one is UB in C. The result of an assignment operator is not an lvalue, and even if it were it’s UB (at least in C99) to modify the stored value of an object more than once between two adjacent sequence points. It might work in C++, though.

  • abbadon420@lemm.ee
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    The third one is just (x=x+1), because the middle bit is just always false and can be ignored.

      • rhpp@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        Still false, thanks to compiler optimizations. Remember that integer overflow is UB. (unless you’re using unsigned int or a programming language which strictly defines integer overflow, possibly as an error)

        P.S.: Assuming this is C/C++