qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2] osdep: Make MIN/MAX evaluate arguments only


From: Richard Henderson
Subject: Re: [Qemu-devel] [PATCH v2] osdep: Make MIN/MAX evaluate arguments only once
Date: Sun, 6 Jan 2019 18:32:03 +1000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1

On 1/6/19 11:38 AM, Eric Blake wrote:
> +/*
> + * Automatic type deduction, to be used as:
> + * QEMU_TYPEOF(expr) name = expr;
> + */
> +#if QEMU_GNUC_PREREQ(4, 9)
> +# define QEMU_TYPEOF(a) __auto_type
> +#else
> +# define QEMU_TYPEOF(a) typeof(a)
> +#endif

What's wrong with always using typeof?  This seems like it leaves potential odd
bugs affecting gcc-4.8.

> +#undef MIN
> +#define MIN(a, b)                            \
> +    ({                                       \
> +        QEMU_TYPEOF((a) + 0) _a = (a) + 0;   \
> +        QEMU_TYPEOF((b) + 0) _b = (b) + 0;   \

If you're promoting the type, why don't you want to promote to the common type
between A and B?  E.g.

  __typeof((a) + (b)) _a = (a), _b = (b);

After all, that's what the result type of (p ? _a : _b) will be.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]