Hello, I wrote:
David Brownell wrote:
+static ssize_t at24_iface_read(struct at24_iface *iface, char *buf, + off_t offset, size_t count)
I think it would have been better to pass 'void *' to these methods, which they could cast to 'struct at24_data *', than to waste memory on storing 'struct at24_iface' within 'struct at24_data' just to make use of container_of() here...
Again, why "better"?
To avoid the useless inclusion of the instance of 'struct at24_iface' into 'struct at24_data' -- that instance, if you insist on using it, should be a 'static const' variable.
What you're doing, is in terms of C++, passing to the class methods the class' Vtable (table containing pointers to the virtual methods to which 'struct at24_iface' quite corresponds) pointer ISO an object pointer's itself; naturally, this would have required the copy of Vtable to be stored in each object which would've been a total waste of memory since all objects of the same class have the same Vtable -- and of course refer it via the single (hidden) pointer member.
... wanting to pass void* as an instance ID
Passing "void *" is generally considered worse than passing values with types that the compiler can verify.
It in no way can verify that 'struct at24_iface' passed via pointer to read()/write() is *indeed* a member of 'struct ata24_data' -- the fact that you've been carefully avoiding to admit so far. This code works based on a cetain assumption about the caller's behavior, not on complier's verification of its validity.
WBR, Sergei _______________________________________________ Davinci-linux-open-source mailing list [email protected] http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source
