Re: glib strlen ?



OK, I'll keep in my mind about the public struct in glib.
I assume the GString struct is valid for read-only.

John K Luebs wrote:

On Wed, Mar 26, 2003 at 10:19:50AM +0700, mige wrote:
Hi folks,

First, thank you for all infos.
It's confirmed that no function in glib for strlen, right ? Both gchar and GString.
Why . May be it's related to i18n, multy-byte characters, etc

I use the strlen, and it's ok for this time.
Is it ok  to access the GString's len member directly ?



Please, no comments from the peanut gallery:

*Using strlen with a GString* is incorrect.*

1) The length is computed for you and stored. You might as well use it.
2) strlen is not correct in terms of GStrings. A valid GString can
contain embedded NULL characters, and strlen will not handle this case.

More importantly, where your confusion is stemming from:

3) The len struct field is public as explained below. In
fact, it is because of the public len field that there is no len
function.
Let me now end your confusion:

I think you were concerned about accessing len, you shouldn't be. len,
allocated_len, and str are all "public" struct fields of the GString.

In general:
When you look at the GTK/glib docs, the fields of structures that are
opaque or that you not supposed to touch do not show up.
All structure fields that are visible in the docs are considered
publicly accessible. Furthermore, public struct fields will not be
duplicated with accessor functions. That is why there is no len function
for GString.

For example, if you look at GTK+ documentation, you will notice that
under the Details heading of most widgets, there are no fields listed
for the structs. Then there are widgets like GtkDialog. A GtkDialog has a
vbox widget and an action_area widget. You will notice there are no
functions for accessing these members. If you look at the Details
section, however you will notice that vbox and action_area are visible.
So it is considered correct to access these struct members.

I agree that this convention should be more prominently highlighted in the
GTK/glib docs. Let me also say


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list






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