[systemd-devel] compile with clang broken

Lennart Poettering lennart at poettering.net
Mon Aug 18 05:24:35 PDT 2014


On Sat, 16.08.14 13:29, Daniele Nicolodi (daniele at grinta.net) wrote:

> 
> On 16/08/2014 12:35, David Herrmann wrote:
> > On Fri, Aug 15, 2014 at 5:22 PM, Daniele Nicolodi <daniele at grinta.net> wrote:
> >> this may be completely stupid, but if the only use case you have for
> >> CONST_MAX() is for computing the size of a data structure, I find
> >> something like
> >>
> >> #define MAXSIZE(A, B) sizeof(union { __typeof(A) a; __typeof(B) b;})
> >>
> >> a little more clear and less magic, and I believe it has the same
> >> guarantees that the solution you found.
> > 
> > Your MAXSIZE macro might add padding:
> 
> > This union has size 8, not 5 (64bit). But CONST_MAX would return 5.
> > Not sure whether that really matters, though. And we could probably
> > add __packed__ to the definition.
> 
> Indeed it does add padding. Adding the __packed__ attribute solves the
> problem:
> 
> #define MAXSIZE(A, B) sizeof(           \
>    union __attribute__((__packed__)) {  \
>       __typeof(A) a; __typeof(B) b;})

I like this actually. I am also fine with CONST_MAX(). I'd also be fine
with having both... ;-)

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list