In this article:
https://lwn.net/Articles/444910/The following method is discussed for setting better defaults of vtables than having NULL in C for the Linux kernel:
#define FOO_DEFAULTS .bar = default_bar, .baz = default_baz
struct foo_operations my_foo = { FOO_DEFAULTS,
.bar = my_bar,
};
The usefulness here is that having a meaningful default method, the test for NULL can be avoided. So instead of:
if (my_foo.bar != NULL) my_foo.bar();
We can simply use:
my_foo.bar();
Since the default method is assumed to be correct for the situation.
Currently in C2, this would not be possible. While I understand the need to "error proof" things, I think this should not be forbidden in C2, and instead produce a warning that can be supressed using an @(override), like this:
#define FOO_DEFAULTS .bar = default_bar, .baz = default_baz
Foo_operations my_foo = { FOO_DEFAULTS,
.bar = my_bar @(override),
};
OR by setting a @(weak) on the default:
#define FOO_DEFAULTS .bar = default_bar @(weak), .baz = default_baz @(weak)
Foo_operations my_foo = { FOO_DEFAULTS,
.bar = my_bar,
};