Hello.

David Brownell wrote:

    Ugh. Don't frighten me with a picture of this container_of() trick
repated in 8 more drivers. :-]

You really need to look at more kernel code.  It's not a "trick",
it's an *EXTREMELY COMMON* idiom that's very widely used when
interfacing ...

In fact, I have only seen this method first in the kernel, so your claim that it's extremely common is highly dountfule to me. But I can say for sure that iut's quite risky idiom because it only works if the code's assumptions of how the data is laid out are true.

it gives information hiding with negligible cost.

It's the first time I hear about such a way of "ïnformation hiding". Abstaction/incapsulation come to mind but I studied that stuff about 20 years ago and in Russian. :-) Usually it's achieved by abstract data types (of which C's 'void *' is the closest approximation :-).

(A constant addition or subtraction, often merged with other
address calculations for a net cost of zero.)

Actually, the container_of() pointer trickery (I cannot call it otherwise) reminds the most of the C++ multiple inheritance -- but that language unlike C warrants that the the parent objects are really a part of the child object, so it's always legitimate to cast (at least pointer to) child's type to parent's (which should result in alike pointer arithmetics).

WBR, Sergei



_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to