The title really says it all: what is the difference between minus one and tilda (ones-complement) zero?
The question came up during a discussion of the best way to specify a bit mask in which all bits are set. Which of the following is better?
int func(int value, int mask = -1) {
return (value & mask);
}
or
int func(int value, int mask = ~0) {
return (value & mask);
}
Are there any other uses where it would be the other way around?
Update: There has been a similar discussion on this topic over at stackoverflow.com/q/809227/34509 which I missed during my prior research. Thanks to Johannes Schaub for pointing it out.