[PATCH] support: Add TEST_COMPARE macro

Andreas Schwab schwab@suse.de
Thu Nov 23 11:09:00 GMT 2017


On Nov 23 2017, Florian Weimer <fweimer@redhat.com> wrote:

> +/* Compare the two integers LEFT and RIGHT and report failure if they
> +   are different.  */
> +#define TEST_COMPARE(left, right)                                       \
> +  ({                                                                    \
> +    __typeof__ (left) __left_value = (left);                            \
> +    __typeof__ (right) __right_value = (right);                         \
> +    /* Prevent accidental use with larger-than-long long types.  */     \
> +    _Static_assert (sizeof (__left_value) <= sizeof (long long),        \
> +                    "left value fits into long long");                  \
> +    _Static_assert (sizeof (__right_value) <= sizeof (long long),       \
> +                    "right value fits into long long");                 \
> +    /* Compare the value and the sign, to avoid false equality.  */     \
> +    /* (A signed value could be converted to an unsigned type.)  */     \

Why do you need that?  Any signed value converted to unsigned is still
unique.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



More information about the Libc-alpha mailing list