Why is this?

int kitty(GtkWidget* widget, float* foo)
{
  if(*foo != .5f)
   std::cout << "this usually occurs" << std::endl;
}
int otherFunc(void)
{
  float foo = .5f;
  //assume widget has been created
  g_signal_connect(G_OBJECT(widget), "clicked", G_CALLBACK(kitty), (gpointer)&foo);
}
int otherFunc(void)
{
  float foo = .5f;
  //assume widget has been created
  g_signal_connect(G_OBJECT(widget), "clicked", G_CALLBACK(kitty), (gpointer)&foo);
}

Wouldn't this foo be destroyed by the time the event handler kitty is called?

Also, do read up on comparing floating point values. http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.