Re: [Fwd: glib integer formatting macros]



On Thu, 11 Mar 1999, Sebastian Wilhelmi wrote:

> Hi, all
> 
> I've got a request from a user. What do you think? IMHO it sounds quite
> reasonable. The syntax is not nice, but better than to get a warning
> everytime. I only seem to remember, that there is a slight difference of
> the formats for printf and scanf (due to the fact, that ellipse parameters
> are always upcasted to long (double), when they are short,int (float)). My
> K&R however states the opposite, does someone know, what ansi/iso
> requires?

yes, gtkargcollector.c implements a generic arg parser btw that takes
care of the different variable widths. basically, everthing with sizeof()
< sizeof(int) will be passed as int, thus longs have to be collected
seperatedly. floats are always passed as doubles.

something like the below macros definitely belong into glib, though the
actuall macros need to be somewhat more genric and comprehensive, i.e.
we should provide G_GUINT_FORMAT and G_GULONG_FORMAT as well if we provide
G_GUINT32_FORMAT (and probably for the rest of the g* types as well for
consistency). also, these macros don't feature '%' flags, so they should
probably be defined without the '%', with that you can do:

#define G_GUINT32_FORMAT "u"
   guint32 n = 7;
   g_print ("Hello agent %03" G_GUINT32_FORMAT "!\n", n);

as an alternative, we could also provide   

#define G_GUINT32_FORMAT(flags)   "%" g_string (flags) "u"
   guint32 n = 7;
   g_print ("Hello agent " G_GUINT32_FORMAT (03) "!\n", n);

but i doubt that this would gain us much in terms of readability.


> 
> Bye, Sebastian
> 
> -- 
> Sebastian Wilhelmi                   |            här ovanför alla molnen
> mailto:wilhelmi@ira.uka.de           |      är himmlen så förunerligt blå
> http://goethe.ira.uka.de/~wilhelmi   |
> 

---
ciaoTJ




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