[Fwd: glib integer formatting macros]
- From: Sebastian Wilhelmi <wilhelmi ira uka de>
- To: GTK+ development list <gtk-devel-list redhat com>
- CC: Sascha Brawer <sb adasys ch>
- Subject: [Fwd: glib integer formatting macros]
- Date: Thu, 11 Mar 1999 16:50:16 +0100
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?
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 |
--------------------------------------------------------------------
Forwarded (slighly edited) message
--------------------------------------------------------------------
> Hi Sebastian,
>
> it would be extremely nice if there was a platform-independent way of
> passing the glib-defined integer types (such as guint32, gint64 etc.) to
> printf(), scanf() and relatives. Currently, there is no way of doing
> this. Therefore, platform-specific code has to be written whenever one
> of the glib integer types is to be passed to printf or scanf. In my
> opinion, this definitely is a missing feature in glib.
>
> Please find below a patch that resolves this issue. However, you might
> want to make sure that the definitions are correct for 32-bit machines,
> since I only have access to 64-bit machines here. Mainly, I am not sure
> whether "%lli" and "%llu" are valid format expressions.
>
> With this patch, it is possible to write code such as:
>
> guint32 blah = 3;
> printf ("Hello " G_GUINT32_FORMAT " you", blah);
>
> Best regards,
>
> -- Sascha
>
> Sascha Brawer, sb@adasys.ch, http://www.coli.uni-sb.de/~brawer
>
> % cvs -z3 diff -u
> cvs server: Diffing .
> Index: configure.in
> ===================================================================
> RCS file: /cvs/gnome/glib/configure.in,v
> retrieving revision 1.91
> diff -u -r1.91 configure.in
> --- configure.in 1999/02/27 00:25:58 1.91
> +++ configure.in 1999/03/08 14:42:48
> @@ -924,6 +924,8 @@
> cat >>$outfile <<_______EOF
> typedef signed $gint16 gint16;
> typedef unsigned $gint16 guint16;
> +#define G_GINT16_FORMAT $gint16_format
> +#define G_GUINT16_FORMAT $guint16_format
> _______EOF
> fi
>
> @@ -932,6 +934,8 @@
> cat >>$outfile <<_______EOF
> typedef signed $gint32 gint32;
> typedef unsigned $gint32 guint32;
> +#define G_GINT32_FORMAT $gint32_format
> +#define G_GUINT32_FORMAT $guint32_format
> _______EOF
> fi
>
> @@ -944,6 +948,8 @@
> ${glib_extension}typedef unsigned $gint64 guint64;
>
> #define G_GINT64_CONSTANT(val) $gint64_constant
> +#define G_GINT64_FORMAT $gint64_format
> +#define G_GUINT64_FORMAT $guint64_format
> _______EOF
> fi
>
> @@ -1100,26 +1106,52 @@
> fi
>
> case 2 in
> -$ac_cv_sizeof_short) gint16=short;;
> -$ac_cv_sizeof_int) gint16=int;;
> +$ac_cv_sizeof_short)
> + gint16=short
> + gint16_format='"%i"'
> + guint16_format='"%u"'
> + ;;
> +$ac_cv_sizeof_int)
> + gint16=int
> + gint16_format='"%i"'
> + guint16_format='"%u"'
> + ;;
> esac
> +
> case 4 in
> -$ac_cv_sizeof_short) gint32=short;;
> -$ac_cv_sizeof_int) gint32=int;;
> -$ac_cv_sizeof_long) gint32=long;;
> +$ac_cv_sizeof_short)
> + gint32=short
> + gint32_format='"%i"'
> + guint32_format='"%u"'
> + ;;
> +$ac_cv_sizeof_int)
> + gint32=int
> + gint32_format='"%i"'
> + guint32_format='"%u"'
> + ;;
> +$ac_cv_sizeof_long)
> + gint32=long
> + gint32_format='"%li"'
> + guint32_format='"%lu"'
> + ;;
> esac
> +
> case 8 in
> $ac_cv_sizeof_int)
> gint64=int
> glib_extension=
> glib_warning_guard=
> gint64_constant='(val)'
> + gint64_format='"%i"'
> + guint64_format='"%u"'
> ;;
> $ac_cv_sizeof_long)
> gint64=long
> glib_extension=
> glib_warning_guard=
> gint64_constant='(val##L)'
> + gint64_format='"%li"'
> + guint64_format='"%lu"'
> ;;
> $ac_cv_sizeof_long_long)
> gint64='long long'
> @@ -1133,6 +1165,8 @@
>
> "
> gint64_constant='(G_GNUC_EXTENSION (val##LL))'
> + gint64_format='"%lli"'
> + gint64_format='"%llu"'
> ;;
> esac
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]