Re: Consensus on getter conventions?



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.

 - Maciej





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