0

Consider the two simple functions:

int return0Comp(){
    return (~0);
}

int returnNeg1(){
    return -1;
}

I know that on a twos-complement system, ~0==-1, but on the off-chance that a system isn't using that (does that even happen?*), will these two functions be returning different values?

galois
  • 825
  • 2
  • 11
  • 31

1 Answers1

2

The standard says [expr.unary.op.10]

The operand of ~ shall have integral or unscoped enumeration type; the result is the one’s complement of its operand.

I read this that ~ always just inverts all the bits, so the interpretation of the result should indeed depend on the representation used.

Petr
  • 9,812
  • 1
  • 28
  • 52