I'm trying to learn more about kobject in linux kernel and while trying to write a module that uses such facility, I was getting error and warning message, so I've put down here the trimmed down version of the relevant data structure and the corresponding gcc's error and warning message.
$ gcc issue.c
issue.c:30:1: error: initializer element is not constant
} ;
^
issue.c:30:1: error: (near initialization for ‘first.attr’)
issue.c:34:1: error: initializer element is not constant
};
^
issue.c:34:1: error: (near initialization for ‘second.attr’)
issue.c:39:8: warning: initialization from incompatible pointer type [enabled by default]
struct bin_attribute *my_bin_attrs[] = { &first_bin_attrs, &second_bin_attrs };
^
issue.c:39:8: warning: (near initialization for ‘my_bin_attrs[0]’) [enabled by default]
issue.c:39:8: warning: initialization from incompatible pointer type [enabled by default]
issue.c:39:8: warning: (near initialization for ‘my_bin_attrs[1]’) [enabled by default]
And the sample code:
#include <stdio.h>
struct attribute {
const char *name;
unsigned short mode;
};
struct bin_attribute {
struct attribute attr;
unsigned int size;
void *private;
};
struct attribute_group {
const char *name;
struct attribute **attrs;
struct bin_attribute **bin_attrs;
};
struct attribute first_attr = {
.name = "FIRST"
};
struct attribute second_attr = {
.name = "SECOND"
};
struct bin_attribute first = {
.attr = first_attr
} ;
struct bin_attribute second = {
.attr = second_attr
};
struct bin_attribute *first_bin_attrs = &first;
struct bin_attribute *second_bin_attrs = &second;
struct bin_attribute *my_bin_attrs[] = { &first_bin_attrs, &second_bin_attrs };
int main(void)
{
struct attribute_group my_group = {
.name = "xyz",
.bin_attrs = my_bin_attrs,
};
return 0;
}