[libvirt] [RFC PATCH] maint: let MIN/MAX evaluate only once, on modern compilers
Eric Blake
eblake at redhat.com
Fri Jan 4 16:23:12 UTC 2019
On 1/4/19 10:00 AM, Eric Blake wrote:
> We might as well take advantage of gcc's extensions for a safer
> MIN()/MAX() macro.
>
> Signed-off-by: Eric Blake <eblake at redhat.com>
> ---
>
> RFC because we could also try to fall back to older gcc's typeof(a)_a=(a)
> when the newer __auto_type _a=(a) is not present, and because I don't
> know how to properly probe for __auto_type and/or typeof support in
> clang (I know that clang added __auto_type in 2015, per
> https://reviews.llvm.org/D12686); I also don't know if we have officially
> stated that we require gcc/clang (because of attribute((cleanup)), which
> really cannot be emulated without extensions), or if we still try to
> allow compilation with other compilers; if we have, I don't know if we
> have declared a minimum compiler version that we demand (qemu has recently
> demanded gcc 4.8 or clang 3.4 [branded 5.1 on Apple]).
Also RFC because:
In file included from util/virlog.c:46:
util/virutil.h:43:22: error: braced-group within expression allowed only
inside a function
# define MAX(a, b) ({ \
^
util/virlog.c:899:29: note: in expansion of macro 'MAX'
# define JOURNAL_BUF_SIZE (MAX(INT_BUFSIZE_BOUND(int), sizeof(uint64_t)))
^~~
util/virlog.c:904:18: note: in expansion of macro 'JOURNAL_BUF_SIZE'
char (*bufs)[JOURNAL_BUF_SIZE], (*bufs_end)[JOURNAL_BUF_SIZE];
^~~~~~~~~~~~~~~~
util/virutil.h:43:22: error: braced-group within expression allowed only
inside a function
# define MAX(a, b) ({ \
^
util/virlog.c:899:29: note: in expansion of macro 'MAX'
# define JOURNAL_BUF_SIZE (MAX(INT_BUFSIZE_BOUND(int), sizeof(uint64_t)))
^~~
util/virlog.c:904:49: note: in expansion of macro 'JOURNAL_BUF_SIZE'
char (*bufs)[JOURNAL_BUF_SIZE], (*bufs_end)[JOURNAL_BUF_SIZE];
^~~~~~~~~~~~~~~~
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190104/beef8ae9/attachment-0001.sig>
More information about the libvir-list
mailing list