[ircd-ratbox] [PATCH] ratbox-services CVS 20050517: gcc 4.1 20050515

Ralf S. Engelschall rse at engelschall.com
Tue May 17 14:14:10 EDT 2005


On Tue, May 17, 2005, Jilles Tjoelker wrote:

> On Tue, May 17, 2005 at 06:59:48PM +0200, Ralf S. Engelschall wrote:
> > The following patch against Ratbox-Services CVS snapshot as of 20050517
> > fixes a type conflict on an assignment, an initialization warning
> > (although the code is correct) and removes two nasty conflicts of "void"
> > pointer vs. function pointer assignment (which is not allowed under
> > strict ISO-C) by using the usual intermediate "union". This allows
> > Ratbox-Services to pass GCC 4.1.0 20050515 even under -Wall -pedantic.
>
> The intermediate "union" (union { hook_func fp; void *vp; } u;) is a
> very bad thing. This means that the code will compile when function
> pointers cannot be assigned to void * and crash at run-time instead of
> failing at compile time. Example: MS-DOS "medium memory model" with
> 16+16 bit function pointers and 16 bit data pointers. I don't think it
> is important to support architectures like these, but they should not
> fail in nastier ways than they already did. In addition, the current
> code is nicer to read than the patched one.

Yes, you're right, on some platforms data and code pointers have
different sizes. I totally forgot this for a while. But how to shut up
the GCC warnings? The only alternative AFAIK is to let ratbox-services
internally always use a real function pointer (usually a generic
"void(*)(void)") instead of a void pointer ("void *") and cast only from
the generic function pointer to the actual one. That's the only fully
portable and clean solution, isn't it?

                                       Ralf S. Engelschall
                                       rse at engelschall.com
                                       www.engelschall.com



More information about the ircd-ratbox mailing list