Hi On Sat, Aug 16, 2014 at 1:29 PM, 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;}) > >> However, I noticed that GCC complains about using >> statement-expressions to initialize static-const structure members, >> even with my 'const' annotations added to MAX. *sigh* >> Thus, I think I'll keep CONST_MAX, as we'd require a 3rd macro otherwise. > > My proposal was based on the fact that the only use of CONST_MAX there > is (was?) in the code was about array size declarations, and I find > MAXSIZE() much easier to understand.
I've added the macro now. Thanks! David _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel