logoalt Hacker News

phendrenad2yesterday at 6:30 PM1 replyview on HN

Tried it on https://www.onlinegdb.com/online_c_compiler Returns 12. If I were designing C, it would return 13. But then again, I'm an assembly programmer.


Replies

topspinyesterday at 6:53 PM

Godbolt: clang and gcc compilers give 12. msvc compilers yield 13.

    #include <stdio.h>

    int main() {
        int a = 5;
        a = a++ + ++a;
        printf("%d\n", a);
        return 0;
    }
x64 msvc v19.50 VS18.2 output:

    example.c
    ASM generation compiler returned: 0
    example.c
    Execution build compiler returned: 0
    Program returned: 0
    13
x86-64 gcc 16.1 output:

    ASM generation compiler returned: 0
    Execution build compiler returned: 0
    Program returned: 0
    12
armv8-a clang 22.1.0 output:

    <source>:5:10: warning: multiple unsequenced modifications to 'a' [-Wunsequenced]
        5 |     a = a++ + ++a;
          |          ^    ~~
    1 warning generated.
    ASM generation compiler returned: 0
    <source>:5:10: warning: multiple unsequenced modifications to 'a' [-Wunsequenced]
        5 |     a = a++ + ++a;
          |          ^    ~~
    1 warning generated.
    Execution build compiler returned: 0
    Program returned: 0
    12