On Sat, 16.08.14 13:29, Daniele Nicolodi (dani...@grinta.net) wrote: > > On 16/08/2014 12:35, David Herrmann wrote: > > On Fri, Aug 15, 2014 at 5:22 PM, Daniele Nicolodi <dani...@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 _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel