GNOME Bugzilla – Bug 346757
GtkTextBufferTargetInfo enumerator is not ansi-C conform
Last modified: 2007-02-05 10:40:40 UTC
Please describe the problem: $ gcc -Wall -O2 -ansi -pedantic -W `pkg-config --cflags --libs gtk+-2.0` main2.c In file included from /opt/gtk/include/gtk-2.0/gtk/gtk.h:170, from main2.c:1: /opt/gtk/include/gtk-2.0/gtk/gtktextbuffer.h:52: warning: ISO C restricts enumerator values to range of 'int' /opt/gtk/include/gtk-2.0/gtk/gtktextbuffer.h:53: warning: ISO C restricts enumerator values to range of 'int' /opt/gtk/include/gtk-2.0/gtk/gtktextbuffer.h:55: warning: ISO C restricts enumerator values to range of 'int' Because use G_MAXUINT for set enumator values : typedef enum { GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS = G_MAXUINT - 0, GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT = G_MAXUINT - 1, GTK_TEXT_BUFFER_TARGET_INFO_TEXT = G_MAXUINT - 2 } GtkTextBufferTargetInfo; Steps to reproduce: 1. $ cat main.c #include <gtk/gtk.h> 2. $ gcc -Wall -O2 -ansi -pedantic -W `pkg-config --cflags --libs gtk+-2.0` main2.c Actual results: Expected results: Does this happen every time? Other information: Remplace enumerator declaration by : typedef enum { GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS = G_MAXINT - 0, GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT = G_MAXINT - 1, GTK_TEXT_BUFFER_TARGET_INFO_TEXT = G_MAXINT - 2 } GtkTextBufferTargetInfo;
Created attachment 68487 [details] [review] Patch
Comment on attachment 68487 [details] [review] Patch >*** ~/gtk+-2.10.0/gtk/gtktextbuffer.h 2006-03-22 11:39:51.000000000 +0100 >--- ~/gtk+-2.10.0/gtk/gtktextbuffer_patch.h 2006-07-06 19:12:52.000000000 +0200 >*************** >*** 50,56 **** > typedef enum > { >! GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS = G_MAXUINT - 0, >! GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT = G_MAXUINT - 1, >! GTK_TEXT_BUFFER_TARGET_INFO_TEXT = G_MAXUINT - 2 > } GtkTextBufferTargetInfo; > >--- 50,56 ---- > typedef enum > { >! GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS = G_MAXINT - 0, >! GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT = G_MAXINT - 1, >! GTK_TEXT_BUFFER_TARGET_INFO_TEXT = G_MAXINT - 2 > } GtkTextBufferTargetInfo; >
Hmm, too bad.
Indeed. I wonder why people who care about stuff like "-ansi -pedantic" don't try a development snapshot from time to time instead of complaining when it's too late.
I ran into this awhile ago but hadn't had a chance to report a bug till now, but for compatibility, all that should be needed is to change the values too GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS = -1, GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT = -2, GTK_TEXT_BUFFER_TARGET_INFO_TEXT = -3 the actual resulting values should be the same because (int)(UINT_MAX - 0) == -1 (int)(UINT_MAX - 1) == -2 (int)(UINT_MAX - 2) == -3 and enums use a signed int in the first place.
It's not a big deal to fix it, is it? This is the only header in GTK which produces warnings with -ansi -pedantic. (In reply to comment #4) > Indeed. I wonder why people who care about stuff like "-ansi -pedantic" > don't try a development snapshot from time to time instead of complaining > when it's too late. I personally don't use it always, since there is always stuff like (gpointer)a_func. But I use it from time to time. What's too late?
Just using -1, -2, -3 would work since these are indeed the same values as MAXUINT - 1, 2, 3. Matthias, what do you think?
*** Bug 398920 has been marked as a duplicate of this bug. ***
Mitch, changing these to -1, -2, etc in the header sounds fine to me.
Please do so, as it makes checking any code with -Werr impossible. Sometimes it's useful to have very strict code, especially when you are compiling for different platforms and using different compilers.
Fixed in both branches: 2007-02-05 Michael Natterer <mitch@imendio.com> * gtk/gtktextbuffer.h (enum GtkTextBufferTargetInfo): changed values from G_MAXUINT-0, -1, -2 to -1, -2, -3 so we stay within ansi C enum value limits. Fixes bug #46757.