This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC] timers, pointers to functions and type safety
- From: Kyle Moffett <mrmacman_g4 at mac dot com>
- To: Al Viro <viro at ftp dot linux dot org dot uk>
- Cc: Linus Torvalds <torvalds at osdl dot org>, linux-arch at vger dot kernel dot org, linux-kernel at vger dot kernel dot org, gcc at gcc dot gnu dot org
- Date: Sat, 2 Dec 2006 04:23:32 -0500
- Subject: Re: [RFC] timers, pointers to functions and type safety
- References: <20061201172149.GC3078@ftp.linux.org.uk>
On Dec 01, 2006, at 12:21:49, Al Viro wrote:
And that's where it gets interesting. It would be very nice to get to
the following situation:
* callbacks are void (*)(void *)
* data is void *
* instances can take void * or pointer to object type
* a macro SETUP_TIMER(timer, func, data) sets callback and data
and checks if func(data) would be valid.
This is where a very limited form of C++ templates would do nicely;
you could define something like the following:
template <typename T>
static inline void setup_timer(struct timer_list *timer,
void (*function)(T *), T *data)
{
timer->function = (void (*)(void *))function;
timer->data = (void *)data;
init_timer(timer);
}
Any attempts to call it with mismatched "function" and "data"
arguments would display an "Unable to find matching template" error
from the compiler.
Unfortunately you can't get simple templated functions without
opening the whole barrel of monkeys involved with C++ support;
including an explosion of reserved words, a 400% or more increase in
compilation time, a decrease in the efficiency of parts of the
generated code, etc.
<crazy-talk>
Maybe it's time for Linux to fork GCC and morph C99 into a language
whose design more fundamentally supports the kinds of type-checking
and static verification that we keep adding to the kernel, including
some of the things that sparse, lockdep, kmemleak, etc. do.
</crazy-talk>
Cheers,
Kyle Moffett