Michel Dänzer writes:
> Is assigning an unsigned value with the MSB set to a signed variable
> well-defined in C?
I have no idea. And I just spent a few hours wading through the N1570
draft of the C standard on a related issue. In particular, this is
worrying:
6.3.1.3
3
On 25/08/17 03:57 AM, Eric Anholt wrote:
> ---
>
> We pass the overflow unit tests both before and after this change, but
> this should be safer.
>
> include/misc.h | 8 ++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/include/misc.h b/include/misc.h
> index
Eric Anholt writes:
> ---
>
> We pass the overflow unit tests both before and after this change, but
> this should be safer.
I've seen GCC do precisely the 'optimization' you are concerned about,
but only when one of the operands is constant. One should use -fwrapv
whenever
---
We pass the overflow unit tests both before and after this change, but
this should be safer.
include/misc.h | 8 ++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/include/misc.h b/include/misc.h
index 0feeaebc7c1a..9d0e422e36b4 100644
--- a/include/misc.h
+++
2017-08-23 22:06 GMT+05:00 Eric Anholt :
> diff --git a/include/misc.h b/include/misc.h
> index 38af70ff9e89..0feeaebc7c1a 100644
> --- a/include/misc.h
> +++ b/include/misc.h
> @@ -324,6 +324,31 @@ bswap_32(uint32_t x)
> ((x & 0x00FF) << 24));
> }
>
> +static