I understand the way I've normally seen inheritance, where:
struct Child {
struct Parent p;
int somethingOnlyForChildren;
}
I see how it all lines up in memory, but in the case of the kernel code I can't quite follow it. Wouldn't everything assigned to 'inherits' be so much farther down in memory? I feel like I'm missing something. Is there a special way they all need to be accessed?
- Peter
On Thu, May 26, 2011 at 7:23 PM, Greg KH <greg@xxxxxxxxx> wrote:
I think you are right, but more subsystems need to emulate it, it isOn Thu, May 26, 2011 at 02:46:08PM -0600, Peter Hamilton wrote:
> The code in drivers/ata/ uses an implementation of inheritance that I have not
> seen before. It's only briefly explained in the header file ( include/linux/
> libata.h:885):
>
> /*
> * ->inherits must be the last field and all the preceding
> * fields must be pointers.
> */
>
> The structs are then initialized with .inherits assigned first:
>
> drivers/ata/sata_nv.c:475
>
> static struct ata_port_operations nv_nf2_ops = {
> .inherits = &nv_generic_ops,
> .freeze = nv_nf2_freeze,
> .thaw = nv_nf2_thaw,
> };
>
>
> Is this actually implementing inheritance? Why do all preceding fields need to
> be pointers?
>
> As far as I can tell, this style is only found in the ata drivers.
very powerful and works very well. I have been wanting to convert the
usb-serial layer to use the same thing one of these days.
The code is all there that shows it, but basically the driver is telling
> Could anyone explain how this works?
the core to "use this type of functions, but if I set any others, use
them instead." It's a nicer way of doing inheritance in C than we do in
other places in the kernel where we are a bit more "verbose" in making
it happen.
hope this helps,
greg k-h
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies