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: Andrew Pinski <pinskia at gmail dot com>
- To: Al Viro <viro at ftp dot linux dot org dot uk>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 01 Dec 2006 19:57:51 -0800
- Subject: Re: [RFC] timers, pointers to functions and type safety
- References: <20061201172149.GC3078@ftp.linux.org.uk>
On Fri, 2006-12-01 at 17:21 +0000, Al Viro wrote:
> There's a bunch of related issues, some kernel, some gcc,
> thus the Cc from hell on that one.
I don't really see how this is a GCC question, rather I see this
as a C question which means this should have gone to either
gcc-help@gcc.gnu.org or the C news group.
> While that is safe (modulo the portability constraint that affects much
> more code than just timers), it ends up very inconvenient and leads to
> lousy type safety.
Why do you say is inconvenient, that shows up all the time in real
code :).
> The thing is, absolute majority of callbacks really want a pointer to
> some object. There is a handful of cases where we really want a genuine
> number - not a pointer cast to unsigned long, not an index in array, etc.
> They certainly can be dealt with. Nearly a thousand of other instances
> definitely want pointers.
Then create an union which contains the two different types of call
back.
You know:
union a
{
void (*callbackwithulong) (unsigned long);
void (*callbackwithptr) (void*);
};
And then you just use the correct in the correct place.
I don't see why there is a mystery about this?
Thanks,
Andrew Pinski
PS don't cross post and I still don't see a GCC development question in
here, only a C one.