After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 346757 - GtkTextBufferTargetInfo enumerator is not ansi-C conform
GtkTextBufferTargetInfo enumerator is not ansi-C conform
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTextView
2.10.x
Other All
: Normal minor
: ---
Assigned To: gtk-bugs
gtk-bugs
: 398920 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2006-07-06 12:52 UTC by sanpi
Modified: 2007-02-05 10:40 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
Patch (693 bytes, patch)
2006-07-06 17:33 UTC, sanpi
none Details | Review

Description sanpi 2006-07-06 12:52:27 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;
Comment 1 sanpi 2006-07-06 17:33:59 UTC
Created attachment 68487 [details] [review]
Patch
Comment 2 sanpi 2006-07-06 17:35:24 UTC
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;
>
Comment 3 Matthias Clasen 2006-07-06 22:29:03 UTC
Hmm, too bad.
Comment 4 Michael Natterer 2006-07-07 10:24:27 UTC
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.
Comment 5 Andrew Johnson 2006-09-04 17:01:00 UTC
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.
Comment 6 Yevgen Muntyan 2007-01-11 13:00:19 UTC
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?
Comment 7 Michael Natterer 2007-01-11 13:22:27 UTC
Just using -1, -2, -3 would work since these are indeed the same values
as MAXUINT - 1, 2, 3. Matthias, what do you think?
Comment 8 Matthias Clasen 2007-01-21 17:58:33 UTC
*** Bug 398920 has been marked as a duplicate of this bug. ***
Comment 9 Matthias Clasen 2007-01-22 15:40:28 UTC
Mitch, changing these to -1, -2, etc in the header sounds fine to me.
Comment 10 Thomas Wood 2007-02-02 22:44:18 UTC
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.
Comment 11 Michael Natterer 2007-02-05 10:40:40 UTC
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.