Verständnisproblem g_signal_connect



  • /**
     * G_CALLBACK:
     * @f: a function pointer.
     * 
     * Cast a function pointer to a #GCallback.
     */
    #define	G_CALLBACK(f)			 ((GCallback) (f))
    
    /**
     * GCallback:
     * 
     * The type used for callback functions in structure definitions and function 
     * signatures. This doesn't mean that all callback functions must take no 
     * parameters and return void. The required signature of a callback function 
     * is determined by the context in which is used (e.g. the signal to which it 
     * is connected). Use G_CALLBACK() to cast the callback function to a #GCallback. 
     */
    typedef void  (*GCallback)              (void);
    
    /**
     * g_signal_connect:
     * @instance: the instance to connect to.
     * @detailed_signal: a string of the form "signal-name::detail".
     * @c_handler: the #GCallback to connect.
     * @data: data to pass to @c_handler calls.
     * 
     * Connects a #GCallback function to a signal for a particular object.
     * 
     * The handler will be called before the default handler of the signal.
     * 
     * Returns: the handler id
     */
    #define g_signal_connect(instance, detailed_signal, c_handler, data) \
        g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
    

    Usage:

    static gboolean
    on_rect_button_press (void* rect, void* obj2, void* data, char* something,void* blue )
    {
      /* bla bla */
      return true ;
    }
    
    g_signal_connect (rect, "button-press-event",
        G_CALLBACK (on_rect_button_press), einvoidstern); // Woher weiß die Funktion 'g_signal_connect', wo sie 'einvoidstern' hingeben soll?
    

    Ich verstehe es grundsaetzlich nicht, wie das ueberhaupt funktionieren soll. Denn die Funktion wird ja in ein void (*f) (void) gecastet. 😞

    Kann mir jemand das erklären?



  • grübel grübel schrieb:

    Ich verstehe es grundsaetzlich nicht, wie das ueberhaupt funktionieren soll. Denn die Funktion wird ja in ein void (*f) (void) gecastet. 😞

    Da wird der Funktionspointer wohl, bevor er aufgerufen wird, nochmal umgecastet.


Anmelden zum Antworten