Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Oh, there are tons of example. Just have a look at anything within glib or gtk. You can see the work of function pointers in work there all the way. </p> <p>Here e.g the initialization of the gtk_button stuff.</p> <pre><code> static void gtk_button_class_init (GtkButtonClass *klass) { GObjectClass *gobject_class; GtkObjectClass *object_class; GtkWidgetClass *widget_class; GtkContainerClass *container_class; gobject_class = G_OBJECT_CLASS (klass); object_class = (GtkObjectClass*) klass; widget_class = (GtkWidgetClass*) klass; container_class = (GtkContainerClass*) klass; gobject_class->constructor = gtk_button_constructor; gobject_class->set_property = gtk_button_set_property; gobject_class->get_property = gtk_button_get_property; </code></pre> <p>And in gtkobject.h you find the following declarations:</p> <pre><code> struct _GtkObjectClass { GInitiallyUnownedClass parent_class; /* Non overridable class methods to set and get per class arguments */ void (*set_arg) (GtkObject *object, GtkArg *arg, guint arg_id); void (*get_arg) (GtkObject *object, GtkArg *arg, guint arg_id); /* Default signal handler for the ::destroy signal, which is * invoked to request that references to the widget be dropped. * If an object class overrides destroy() in order to perform class * specific destruction then it must still invoke its superclass' * implementation of the method after it is finished with its * own cleanup. (See gtk_widget_real_destroy() for an example of * how to do this). */ void (*destroy) (GtkObject *object); }; </code></pre> <p>The (*set_arg) stuff is a pointer to function and this can e.g be assigned another implementation in some derived class.</p> <p>Often you see something like this</p> <pre><code>struct function_table { char *name; void (*some_fun)(int arg1, double arg2); }; void function1(int arg1, double arg2).... struct function_table my_table [] = { {"function1", function1}, ... </code></pre> <p>So you can reach into the table by name and call the "associated" function. </p> <p>Or maybe you use a hash table in which you put the function and call it "by name".</p> <p>Regards <br> Friedrich</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload