Subject: Re: struct ifnet's if_softc field?
To: Dave McConnell <davem@eastcoast.co.za>
From: Olaf Seibert <rhialto@polder.ubc.kun.nl>
List: tech-kern
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
> 
> if_attach(&sc->sc_if);
> 
> 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.

> Dave
-Olaf.
--
___ Olaf 'Rhialto' Seibert - rhialto@polder.ubc. ---- Unauthorized duplication,
\X/ .kun.nl ---- while sometimes necessary, is never as good as the real thing.