Re: [Fwd: dereferencing void *]



On 03/23/2014 08:36 PM, Joël Krähemann wrote:

The following will compile but is it still correct?

  g_atomic_pointer_set(&(returnable_thread->safe_data),
                       NULL);
http://developer.gimp.org/api/2.0/glib/glib-Basic-Types.html#gpointer
typedef void* gpointer;

http://developer.gimp.org/api/2.0/glib/glib-Atomic-Operations.html
void g_atomic_pointer_set (volatile gpointer *atomic, gpointer newval);

struct _AgsReturnableThread
{
  AgsThread thread;
  volatile guint flags;
  volatile void *safe_data;  // volatile gpointer safe_data
};

safe_data holds the address pointing to a void value(unassigned type).
By putting &(blah->safe_data), you are asking for the address of the
address pointing to a void value.  That's not what you want.

Just put (blah->safe_data, NULL).
The compiler shouldn't complain.
If it does, you could cast blah->safe_data with
(volatile void*)(blah->safe_data)

or

(volatile gpointer)(blah->safe_data)

Both equate to the same thing for the compiler.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]