0

following this link

I did:

static const struct attribute const *attrs1= {
        &foo_attribute.attr,
        NULL,
};
 static const struct attribute_group const attr_group = {
       .attrs = attrs1,
};

but get these errors:

error: initializer element is not constant
error: (near initialization for 'attr_group.attrs')

found this solution but didn't understand how to solve it...

EDIT: the line triggered the error:

.attrs = attrs1,
Community
  • 1
  • 1
0x90
  • 39,472
  • 36
  • 165
  • 245

1 Answers1

2

Yes, another struct object or the contents of another variable will never be considered a constant expression that could be used in an initializer for a static object.

But your first initialization also is bogus. Probably you meant

static const struct attribute * const attrs1= &foo_attribute.attr;

So your initialization of the second would read something like

static const struct attribute_group attr_group = {
       .attrs = &foo_attribute.attr,
};
Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177