On 2012-01-25 00:03, Anthony Liguori wrote:
They're exactly the same size (16 lines). If you embed TypeInfo into
DeviceTypeInfo, and introduce a Device specific type registration
function, then you could do:
static DeviceTypeInfo my_device_type_info = {
.type.name = TYPE_MY_DEVICE,
.type.parent = TYPE_PARENT_DEVICE,
.reset = my_device_reset,
And if you introduce some
#define TYPE_UNIMPLEMENTED (void *)&dummy_variable
you can easily express
[.field = NULL] => use parent
.field = UNIMPLEMENTED => don't run any handler
};
static void register_devices(void)
{
device_type_register_static(&my_device_type_info);
}
Which admittedly saves 6 lines, but also is a big step backwards IMHO.
Now you've got a lot of one-off functions which means you loose the
advantage of having everything work through the same infrastructure.
Can't follow. Four lines
[static inline] void device_type_register_static(DeviceTypeInfo *dt)
{
type_register_static(&dt->type);
}
are neither ugly nor complex. Rather, this helps concentrating effort at
_central_ places instead of decentralizing and duplicating lines like in
your imperative approach. That's the whole point: keep the common case
(derived classes) compact.