On Fri, 8 Oct 2021, LIU Hao wrote:
在 10/7/21 5:54 PM, Martin Storsjö 写道:
+ ptrdiff_t max_unsigned = (1LL << bits) - 1;
+ ptrdiff_t min_signed = (~(ptrdiff_t)0) << (bits - 1);
The idea sounds correct. However it is undefined behavior to shift a negative
number to the left, so would you like to change the second line to
```
ptrdiff_t min_signed = UINTPTR_MAX << (bits - 1);
```
Thanks, that sounds good to me. IIRC, casting an unsigned value to signed,
with the sign bit set, is only implementation defined behaviour, not
undefined behaviour, and thus is ok (as we assume 2s complement)?
As the other uses a `long long` constant, do you prefer `ULLONG_MAX` to
`UINTPTR_MAX`?
I think I prefer UINTPTR_MAX as that's closer to what I mean, I just used
1LL on the other one as that's a more convenient syntax than the ways of
declaring literals of the more specific types.
// Martin
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public