beaver-devel
[Top][All Lists]
Advanced

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

Re: [Beaver-devel] beaver_box_prompt


From: Double 12
Subject: Re: [Beaver-devel] beaver_box_prompt
Date: Sun, 14 Sep 2008 20:32:58 +0200
User-agent: Thunderbird 2.0.0.16 (X11/20080724)


Thanks, your approach worked fine! The only problem is that I can't free the pointer, because I still need it as return value.

Double 12


Um Sat, 13 Sep 2008 21:59:17 +0200
 schrieb Double 12 <address@hidden>:
Surprisingly, gtk_entry_get_text returns a *const*
gchar*.

Did not know that it is possible to return const variables.
obviously it is ^^

This is because the function returns a pointer to
a string that "points to internally allocated storage in
the widget and must not be freed, modified or stored".
I saved the result of the gtk_entry_get_text function in
a const gchar* and used that as return value for the
function beaver_box_prompt_impl.
The weird thing is: if I print the text (extracted from
the entry) directly in the beaver_box_prompt_impl
function, it is displayed correctly. If I try to print
the text in the  function it is called from
(sample_clicked in sample.c), I get weird characters.
You will see it it if you download the latest commits
from the CVS and then compile.

Well it isn't that weird if you look at your statement
("points to internally allocated storage"). when you
destroy the widget (and this you probably do in
beaver_box_prompt_impl) then this internal storage is
freed. what you actually have to do is, is duplicating the
string into a "non-internal" space (aka. heap memory). this
you could do via g_strdup() (this returns a gchar* that has
to be freed). then it should work.
greets
Tobias


_______________________________________________
Beaver-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/beaver-devel




reply via email to

[Prev in Thread] Current Thread [Next in Thread]