[Mono-devel-list] Prevalence of pointer-integral-pointer casting in mono?

Raja R Harinath rharinath at novell.com
Mon Aug 2 00:45:26 EDT 2004


Peter Williams <peter at newton.cx> writes:

> On Sun, 2004-08-01 at 21:23, Jonathan Pryor wrote:
>> I'm not sure about Mono, but glib (one of Mono's dependencies) does
>> this.  It is generally assumed that a gint can be held in a gpointer.
> The GPOINTER_TO_UINT and GUINT_TO_POINTER macros are used to address
> this problem. I'm no expert on this issue, but I'm pretty sure GLib
> shouldn't have this problem. 

The purpose of GPOINTER_TO_UINT and GUINT_TO_POINTER is to carry an
integer in a pointer, not vice versa.  Several callback functions
provide a 'gpointer' to pass user closure data.  If you just have an int
to pass as the callback closure, you can use GUINT_TO_POINTER to encode
it, and decode it with GPOINTER_TO_UINT in the callback function.

So, the "problem" is integer-pointer-integer casting -- which should be
fairly portable.

- Hari

More information about the Mono-devel-list mailing list