Re: Consensus on getter conventions?
- From: Karl Nelson <kenelson ece ucdavis edu>
- To: Maciej Stachowiak <mjs eazel com>
- Cc: kenelson rainbow ece ucdavis edu, gnome-hackers gnome org,gtk-devel-list gnome org
- Subject: Re: Consensus on getter conventions?
- Date: Thu, 24 Aug 2000 17:34:01 -0700
> Derek Simkowiak <dereks@kd-dev.com> writes:
>
> > -> My personal preference is to have all get_* functions which return
> > -> something be a pointer to a "static" piece of memory. Those
> > -> cases where deallocation is required should return by argument.
> > ->
> > -> /* this doesn't need to be freed because it was the return */
> > -> const gchar* gtk_widget_get_name(GtkWidget*);
> > ->
> > -> /* this one does need to be free and it is different for that reason */
> > -> void gtk_font_selection_dialog_get_font_name(
> > -> GtkFontSelectionDialog *fsd, gchar**);
> > -> ^^^^^
> > -> notice it isn't const because we give it to the user.
> >
> > I like Karl's idea. Makes it clear as day.
> >
>
> Karl's idea makes getters that return references pretty
> inconvenient to use from C; you must use a temporary variable even if
> you're going to pass the result to a function that will assume
> ownership.
That was sort of the idea. After all we want to keep someone
from doing something like...
gtk_widget_get_name(w,gtk_font_selection_dialog_get_font_name(w2));
After all how many function assume ownership? I would guess very few as it
is against policy to assume ownership. Thus we really do want
them to make a local variable whenever they use things that
pass ownership.
--Karl
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]