Re: gtk_label_get_text() string duping
- From: Tim Janik <timj gtk org>
- To: Federico Mena Quintero <federico helixcode com>
- Cc: Gtk+ Developers <gtk-devel-list gnome org>
- Subject: Re: gtk_label_get_text() string duping
- Date: Wed, 28 Jun 2000 16:57:42 +0200 (CEST)
On 28 Jun 2000, Federico Mena Quintero wrote:
> Tim Janik <timj@gtk.org> writes:
>
> > a) a function returning a reference should be the normal getter
> > interface of an object. so say oyu have an object foo, that
> > holds a string gchar *bar; you provide an accessor:
> > gchar* foo_get_bar (Foo *foo) { return foo->bar; }
> > (we don't enforce "const" in return values for a variety
> > of reasons that have been discussed before. if we did,
> > this function would return const gchar*)
>
> I know you hate me, Tim, but such a function should return a const
> char *. That way it becomes obvious from looking at the function
> prototype that you should not touch the returned value.
i don't hate you, in fact you're right ;)
just "const" can be a pain in the ass for C programers as some
code const-correct and others don't. those that do will use
const char *my_label = gtk_label_get_text (foo);
and are fine, while those that don't will do:
char *my_label = gtk_label_get_text (foo);
and get a warning if gtk_label_get_text() returns const gchar*.
to impose the least restrictions on our users, we do take "const gchar*"
for arguments, but only use gchar* for return values.
> IMNSHO the GNOME Programming Guidelines got this right.
>
> As Owen pointed out this has issues with threading, but hey, what the
> hell :-)
that's a problem only occouring at the glib level and only needs to
be solved _there_ ;)
>
> Federico
>
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]