GNOME Bugzilla – Bug 519137
g_slice_dup macro needs cast for 64-bit platform
Last modified: 2008-04-10 21:40:40 UTC
The g_slice_dup macro produces a warning under gcc 4.1.3. For example, with the following code snippet lf_lag_frame_t *new_key = g_slice_dup(lf_lag_frame_t, lf); I get this error upon compilation: wcbe_sort.c:1494: warning: cast to pointer from integer of different size This warning presents me with a problem when compiling with the gcc -Werror flag. I have found a modification to the g_slice_dup macro to solve the problem. $ diff /usr/include/glib-2.0/glib/gslice.h gslice.h.new 57c57 < (1 ? g_slice_copy (sizeof (type), (mem)) : (type*) ((type*) 0 == (mem))) --- > (1 ? g_slice_copy (sizeof (type), (mem)) : (type*) GINT_TO_POINTER ((type*) 0 == (mem))) Of course, there might be better ways to solve the problem, but you get the idea.
(In reply to comment #0) > > (1 ? g_slice_copy (sizeof (type), (mem)) : (type*) GINT_TO_POINTER ((type*) 0 == (mem))) thanks a lot for reporting and working out a fix. bratsche,tbf, can you please apply this?
Wouldn't it be cleaner to use comma operator instead? (1 ? g_slice_copy (sizeof (type), (mem)) : ((void) ((type*) 0 == (mem)), (type*) 0)) There's also another problem with this macro: its type is gpointer (that's what g_slice_copy returns) and it should be "type *" according to the pseudo prototype in the header. Existing definition allows you to assign g_slice_copy(...) to any pointer variable without type errors. With additional correction the macro would look like this: (1 ? (type*) g_slice_copy (sizeof (type), (mem)) : ((void) ((type*) 0 == (mem)), (type*) 0))
(In reply to comment #2) > Wouldn't it be cleaner to use comma operator instead? > (1 ? (type*) g_slice_copy (sizeof (type), (mem)) : ((void) ((type*) 0 == > (mem)), (type*) 0)) thanks, this looks indeed preferrable. Bratsche, tbf, can you please commit this?
Bug 519137 – g_slice_dup macro needs cast for 64-bit platform * glib/gslice.h (g_slice_copy): Apply type casts needed for proper compilation on 64-bit platforms.