Re: strsplit question (glib)



Peter Jay Salzman <p dirac org> writes: 
> ok, so now search_path points to an array of strings.  the docs don't
> say a "NULL terminated array of strings".  just an array of strings.
> 
> how do i know how many strings are being pointed to?  in other words,
> how do i use this array when i have no idea how many elements are in
> this array?

It is NULL terminated, this is just a glib convention (all the string
util things that deal with arrays of strings deal with NULL-terminated
arrays in which each string in the array is a separate malloc'd
block).

Probably not in the docs since the docs author considered it obvious
(without NULL termination there's no way the API could possibly work, 
and it's a glib-wide convention anyhow). But might be nice to add to
the docs.

> another question -- glib provides a GString.  perhaps the most useful
> thing in glib.  why in the world would g_strsplit work with arrays of
> char *'s instead of g_arrays of GStrings?

Because g_strsplit() is a utility function for handling C strings, not
GStrings.

Most apps use GString only when building up a string with lots of
appends or the like, and use plain char* for most strings.  A GArray
of GString would be a really error-prone, cumbersome pain in the ass.

Havoc



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