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):<div><br><div>/* </div><div> * ->inherits must be the last field and all the preceding</div>
<div> * fields must be pointers.</div><div> */</div></div><div><br></div><div>The structs are then initialized with .inherits assigned first:</div><div><br></div><div>drivers/ata/sata_nv.c:475</div><div><br></div><div><div>
static struct ata_port_operations nv_nf2_ops = { </div><div> .inherits = &nv_generic_ops,</div><div> .freeze = nv_nf2_freeze, </div>
<div> .thaw = nv_nf2_thaw, </div><div>}; </div></div><div><br></div><div><br></div><div>Is this actually implementing inheritance? Why do all preceding fields need to be pointers?</div>
<div><br></div><div>As far as I can tell, this style is only found in the ata drivers. </div><div><br></div><div>Could anyone explain how this works?</div><div><br></div><div>Thanks,</div><div>Peter</div>