[systemd-devel] compile with clang broken

Daniele Nicolodi daniele at grinta.net
Sat Aug 16 04:29:07 PDT 2014


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;})

> 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.


Cheers,
Daniele



More information about the systemd-devel mailing list