Re: Compiler error with g_string{_append}_printf



On Fri, Dec 17, 2004 at 01:36:17AM -0800, Brian J. Tarricone wrote:
David wrote:

I've come across something that has me baffled - it may be obvious, but
I've fooled with this and can't see what's wrong..

[snip]

  msg = g_string_append_printf (msg, "  -- G09Dis V %s --\n\n%s\n%s", 
  "2.0",
                     "  A graphical front-end to \"os9disasm\"\n",
                     "  This version is strictly BETA!!!");


there's the problem.  g_string_append_printf() doesn't return anything.  
it takes a GString as the first argument, and appends your 
format+arguments to it.  that's it.  the "msg =" is unnecessary, and 
that's what's causing the error.

Oh WOW!  I knew it had to be something simple..  I didn't study the API
close enough I guess, but I realized that the non-printf functions _did_
return the GString * and simply extended this to the printf-variety.. But
now I'm wondering ..

Why would g_string_append need to return the GString pointer and
g_string_append_printf not?  You're modifying the string in both cases.
I now notice that none of the *printf* functions return a value while
the non-printf functions do.

Actually, I can't see why the GString would ever have to change anyway.
It's a structure which contains a pointer to the actual string as one of
its elements.. From my perspective, there's no need for the GString
structure to ever move, but just change the values in its elements.

The return of the GString * could be a convenience for the programmer,
where you could nest your functions, ..like g_printf(
g_string_append(...)), but if this is the only reason, it would be just
as useful with the printfs, too.

Now that I see this difference, it's not a problem, but from my
superficial overview, it seems to be a (slight) inconsistency.

Thanks for clearing this up for me.  As I said, I got around it by
dealing with gchar *, but it was bugging me as to why it was happening.



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