Hello, I 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.
See the recent example [1] , (original BUG report at [2]) for an
example how rudely this fails if the code wasn't correct in its assumptions.
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. :-)
Or slightly less than 20...
Usually it's achieved by abstract data types (of which C's 'void *' is
the closest approximation :-).
No, the closest C approximation would be a pointer to incomplete
struct/union type -- forgot about it (though this is used in the kernel
quite often).
address calculations for a net cost of zero.)
(A constant addition or subtraction, often merged with other
It's always subtraction (or nothing in the best case) in case of
container_of().
[1] http://marc.info/?l=linux-ide&m=121969639715938
[2] http://marc.info/?l=linux-ide&m=121925552315801
WBR, Sergei
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source