Oleg, all,

Just as one data point, modern compilers are able to optimise out function 
pointers if they are constant.  That is, if the struct containing the function 
pointer is a const struct, in a typical case "static const", then e.g. LLVM is 
able to optimise the function pointer call into the resolved function call, 
even during linking time.  I'm not sure if GCC can do that in link time, but if 
the struct is defined as a static struct in a header file, it is able to 
optimise out the struct, including any function pointers in it.

Of course, some care is needed to make sure that the compiler does the right 
thing.  It is relatively easy to break the pattern.

--Pekka

> On 2015–02–18, at 12:38 , Oleg Hahm <oliver.h...@inria.fr> wrote:
> 
> Dear remodeling IoTlers!
> 
> Ludwig just made me aware that Joakim's PR for NVRAM [1] introduces function
> pointers as part of the device driver struct. This made me remember that there
> were already similar function pointers introduced as part of netdev.
> 
> As I was always opposed to use function pointers in that way, I could not
> recall what was the reason to use them for netdev. I don't like this pseudo
> object oriented C style (dev->write() and the like) because we made bad
> experiences with it at my former company. While writing the whole HAL for our
> firmware there using function pointers this way, made programming pretty
> convenient, it turned out to become problematic speed-wise and was a nightmare
> to debug.
> 
> Hence, I would like to trigger a fundamental discussion on this topic. Does
> anyone has a particular opinion on the topic why function pointer based
> device drivers should be a good or a bad idea? And can anyone explain to me
> the need of function pointers for netdev?
> 
> Cheers,
> Oleg
> 
> [1] https://github.com/RIOT-OS/RIOT/pull/2353
> -- 
> if (user_specified)
>    /* Didn't work, but the user is convinced this is the
>     * place. */
> linux-2.4.0-test2/drivers/parport/parport_pc.c
> _______________________________________________
> devel mailing list
> devel@riot-os.org
> http://lists.riot-os.org/mailman/listinfo/devel

_______________________________________________
devel mailing list
devel@riot-os.org
http://lists.riot-os.org/mailman/listinfo/devel

Reply via email to