Re: Strange Casting Problem


Subject: Re: Strange Casting Problem
From: Dom Lachowicz (cinamod@hotmail.com)
Date: Tue Feb 06 2001 - 10:41:31 CST


Sam TH wrote:
>As part of my fun autoconfiscation of the AbiWord tree (It Links, It
>Runs) I came across some very strange errors involving casting from a
>void * to an enum. The compiler didn't like the casts, basically, and
>wouldn't accept them. They look like this:
>
>fp_PageSize::Type foobar = (fp_PageSize::Type) gtk_function_here(with,
>arguments)
>
>This won't compile.
>
>Changing it to this fixes it.
>fp_PageSize::Type foobar = (fp_PageSize::Type) (unsigned int)
> gtk_function_here(with, arguments)
>
>However, the degree to which this is ugly and disgusting boggles the
>mind.
>
>So, two questions here:
>
>1) Why am I getting these errors on the autoconfiscated build, and not
>on normal builds? I have none of the fun warning and ansi options
>set.
>
>2) Why are functions that should be giving us an enum, or something
>vaguely like it, giving us a void *?
>
>The patch to make all the errors go away is attached. But I *really*
>don't like it.
>
>Ideas?

This function that Havoc refers to is gtk_object_get_data() why is by nature
type-unsafe (it accepts/returns a gpointer). The preferred way to insert/get
stuff from it is to use the GPOINTER_TO_INT () macro (and then I'll have to
cast *that* to a fp_PageSize::enum) which I will change the code to do, and
hopefully it will work for your build, Sam.

Dom

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



This archive was generated by hypermail 2b25 : Tue Feb 06 2001 - 10:41:34 CST