Re: some newbie g_signal_connect questions



Matthias Mann wrote:

 but what's about callback functions? They don't need 'return;'.
 Right?

Depends on the use of the callback function. Callback handlers for some
events (i.e. "delete_event", see
http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#GtkWidget-delete-event)
have to return a (gboolean) value while most others don't have to. They
could return values anyway but those would be ignored by GTK.

 But if i have a function with 'return;' cause regular function
 calls it and also a callback function. Could this make problems
 for an application?

Not necessarily. Call your callback function whenever you want. As long
as you call it with the correct parameters it doesn't matter whether it
returns something or not and whether you ignore the returned value or
not. Just be very careful about side-effects from inside the function!

If the callback function is an event handler, designed to act on the
event, it's no good idea to call it manually without the event having
happened. For instance, your on_delete_event-handler (for GtkWindows)
shouldn't be called manually. It wouldn't delete (close) the window.
It's rather meant as a possibility to react on a request to delete the
window, i.e. possibly abort deletion. Call gtk_widget_destroy ()
(http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#gtk-widget-d
estroy) to trigger the event and get the callback called in a proper
way.

 And by the way: a "void" function, does it need this 'return;'?
 Or could i leave it generally?

It doesn't need it as its last statement. It's a matter of coding style
whether you put a "return" as the last statement of a void function or
not. The next two snipplets produce exactly the same code:

    void my_function (<any_parameters>) {
        <do_something>
    }

and

    void my_function (<any_parameters>) {
        <do something>
        return;
    }

However, you might want to return somewhere earlier in a function, on a
given condition. Then you need the "return"-statement anyway.

    void my_function (<any_parameters>) {
        if (<abort_condition_met>)
            return;
        <do_something_else>
    }



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