Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This seems to work. The compiler has to see the previous add to know what is in the carry flag.

    #include <stdint.h>

    uint64_t addWithCarry(uint64_t x, uint64_t y, uint64_t z) {
        return x + y + (y + z < y);
    }
Output here: https://godbolt.org/z/zfP7PnGcs


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: