Re: Naked GString operations [was: Re: Some new GString functions - constructors]



On Wed, Dec 21, 2005 at 12:07:14AM +0000, Paul LeoNerd Evans wrote:
> > >   void g_string_init(GString *str);
> > >   void g_string_fini(GString *str);

Actually, it occurs to me. If we wanted to give certain future
guarantees about GString, we could do something like the following:

  #define GSTRING_STATIC_INIT { .str = NULL; .len = 0; .allocatedlen = 0; }

  ...

  GString s = GSTRING_STATIC_INIT;

in the case of local or global variables, of only one GString (i.e. the
common case). This wouldn't work for arrays or other weird cases, but it
would avoid even the need for a call to the function to initialise it.

The downside here is that the initial representation of an "empty"
GString would need to be compile-time constant, if it would be used in
this manner.

Thoughts?

-- 
Paul "LeoNerd" Evans

leonerd leonerd org uk
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/

Attachment: signature.asc
Description: Digital signature



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