[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-devel] Proposing change to netif state member
From: |
Bill Auerbach |
Subject: |
Re: [lwip-devel] Proposing change to netif state member |
Date: |
Mon, 19 Mar 2012 15:30:04 -0400 |
>-----Original Message-----
>From: address@hidden
>[mailto:address@hidden On
>Behalf Of Sprow
>Sent: Monday, March 19, 2012 2:37 PM
>To: 'lwip-devel'
>Subject: Re: [lwip-devel] Proposing change to netif state member
>
>In article <address@hidden>,
> Bill Auerbach <address@hidden> wrote:
>> It would be nice to override the void type in void *state in struct
>> netif.h.
>> This is the pointer to be used by the Ethernet hardware port or other
>> user-code and it would be nice to use it with the correct type instead
>of
>> casting whenever it's used.
>
>I just use
>
> err_t some_netif_function(struct netif *netif)
> {
> ethernetif_t *netstate = netif->state;
> :
> netstate->mything = 1;
> netstate->stuff++;
> :
> return ERR_OK;
> }
This is fine, yes. You will still need a cast here in a C++ environment.
You're right on the code savings. Where I was casting netif->state is where
I have 4 or 5 one-liners to extract something simple from the low-level
driver (packet counts, link state, connect speed, etc). I suppose even with
your example a decent compiler will optimize the reference to netstate away.
You do gain seeing into the state pointer in a debugger and seeing the type
it points to.
>> #define NETIF_STATE_TYPE struct myPortDescriptor *
>
>Please at least leave the '*' with the state!
True, I do in fact agree but does mean you can't use a typedef'ed pointer.
Personally I don't care for them - it does seem to be common in Windows API
stuff.
Bill