Re: idea: g_alloca_printf



On Thu, 25 Aug 2005, Stefan Kost wrote:

> gchar *status=g_strdup_printf(_("Loading file \"%s\""),file_name);
> g_object_set(G_OBJECT(self),"status",status,NULL);
> g_free(status);
>
> This has the advantage that it framents memory with small strings. When e.g.
> serializing xml it can matter. A solution is:


alloca has several pitfalls and better be avoided.  An
alternative solution is to use g_string_printf.


> #define g_alloca_printf(str,format,...) \
> (sprintf((str=g_printf_upper_bound(format,args)),format,...),str)
>
> * how to get from '...' to 'args'

"..." in macros is not portable.

> Any ideas folks?
>
> Stefan

--behdad
http://behdad.org/



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