Search code examples
cmathintundefinedunsigned

C: confirmation of simple arithmetic output


Can I confirm that the following C code gives undefined result for b:

unsigned a = 0;
int b = a - 1;

Solution

  • (§6.3.1.3/3): "...either the result is implementation-defined or an implementation-defined signal is raised."

    On typical twos-complement hardware, I'd expect the result to be -1.

    Note that the result is implementation defined, not undefined.