On Sat, May 28, 2005 at 05:18:39PM -0700, Caitlin Bestler wrote:
> Verus..
>
> struct rdma_xyz {
> /* common fields */
> };
>
> struct rdma_xyz_ib {
> struct rdma_xyz common;
> /* ib fields */
> };
>
> struct rdma_xyz_iwarp {
> struct rdma_xyz common;
> /* iwarp fields */
> };
>
>
> The latter style is extensible, but makes it difficult to properly
> allocate a buffer that works for all variants.
The latter assumes the transport specific code is owns responsibilty
for allocating/deallocating those buffers.
It also forces the generic code to be completely ignorant of
the transport specific stuff. It doesn't allow the programmer
to hacking around in the "public" unions.
> The union style is also already in use in both IT-API and RNIC-PI.
>
> I personally prefer sub-classing to unions, but I have found myself in the
> minority on *most* projects where the issue has been discussed.
> One reason is that sub-classing provides very little type-safety.
> struct sockaddr is an example of this. It takes manual inspection
> to ensure that the variants are properly differentiated and it is
> still common for developers to pass in a plain struct sockaddr
> without realizing that it is not large enough for a struct sockaddr_in6.
IMHO, unions are a sort of "casts on whole structures".
Neither method really offers an advantage in type checking.
Both require one "knows" which type is the right one.
grant
_______________________________________________
openib-general mailing list
[email protected]
http://openib.org/mailman/listinfo/openib-general
To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general