In article <(E-Mail Removed)>

http://www.velocityreviews.com/forums/(E-Mail Removed) writes:

> John Devereux wrote:

> > I was wondering what is the "best" way to set a variable to "all

> > ones". In particular where I do not know the precise type of the

> > variable (or more accurately, when I don't want to worry about it!).
....

> > E.g. assume "a" is unsigned, but could be char, short, int or long.

> > a = -1;

>

> Yes, always

>

> > a = ~0;

>

> Should be ~0u, instead.

> The type of ~0 is int,

> and the value of ~0 depends on binary representation.

> In sign and magnitude, ~0 is -INT_MAX.

> In one's complement ~0 is negative zero, equal to zero.

> Assignement is by value.
Yup, the value is not -1, but all bits are set to 1. This contradicts

your first "yes always".

--

dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131

home: bovenover 215, 1025 jn amsterdam, nederland;

http://www.cwi.nl/~dik/