Subject: Re: struct ifnet's if_softc field?
To: Dave McConnell <firstname.lastname@example.org>
From: Olaf Seibert <email@example.com>
Date: 05/14/1999 14:19:07
On Fri, 14 May 1999, Dave McConnell wrote:
> Isn't ifnet always the first field in a network drivers softc structure?
> In which case the pointer to the drivers "struct softc" is also the
> address of the devices "struct ifnet" (analogous to inheritence in
> C++) or am I missing something here ?
That would be correct.
> Along the same lines, I also see explicit useage of the softc's ifnet
> field address rather than the address of the softc structure itself
> when an ifnet address is required.
> e.g. from the SLIP code
> where IMHO
> if_attach( (struct ifnet*)sc ) would do.
Well, the first version does not require a cast. That is Good.
It keeps working if somebody for some reason rearranges the order.
AmigaOS has quite a lot of this. Things you put in a List always start
with a Node, and the (system supplied) List manipulation functions take
Node *s as arguments. If you use casts to convert (MyNode *)s to (Node
*)s, it is easy to make mistakes the compiler does not catch. I learned
to use the first style.
___ Olaf 'Rhialto' Seibert - firstname.lastname@example.org. ---- Unauthorized duplication,
\X/ .kun.nl ---- while sometimes necessary, is never as good as the real thing.