[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freedesktop-xorg
Subject:    Compiler warnings unnecessarily caused by X11 headers
From:       Peter Breitenlohner <peb () mppmu ! mpg ! de>
Date:       2009-09-29 13:33:34
Message-ID: alpine.LNX.2.00.0909291519230.16107 () pcl321 ! mppmu ! mpg ! de
[Download RAW message or body]

Hi,

it may be useful to compile programs with
 	gcc -Wall -Wwrite-strings -Wcast-qual
but unfortunately doing this causes numerous compiler warnings when defining
X11 resources.  Attached is a small example resulting in 13 warnings
 	8 initialization discards qualifiers...
 	5 cast discards qualifiers...

All this is due to struct members declared as 'char *' or (char *) casts,
that actually should be 'const char *' or maybe '_Xconst char *'.

I'd think that it is about time to make these changes (knowing well that
they will imply corresponding changes in many other declarations).

Doing this right will, however, also be a good check that these string are
not modified by the X11 library code.

Regards
Peter Breitenlohner <peb@mppmu.mpg.de>
["play.c" (TEXT/plain)]

/* compile with:
 *	gcc -O2 -Wall -Wwrite-strings -Wcast-qual -c play.c
 */

#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>

extern XtResource mf_resources[];
extern XrmOptionDescRec mf_optiondesclist[];

static unsigned int mf_defwidth = 0;

typedef struct
{
  unsigned int mf_width;
  Pixel mf_fg;
} mf_resources_struct;

XtResource mf_resources[] = { {
  "width",		/* initialization discards qualifiers... */
  "Width",		/* initialization discards qualifiers... */
  XtRInt,		/* cast discards qualifiers... */
  sizeof (int),
  XtOffset (mf_resources_struct *, mf_width),
  XtRInt,		/* cast discards qualifiers... */
  (XtPointer) & mf_defwidth
}, {
  "foreground",		/* initialization discards qualifiers... */
  "Foreground",		/* initialization discards qualifiers... */
  XtRPixel,		/* cast discards qualifiers... */
  sizeof (Pixel),
  XtOffset (mf_resources_struct *, mf_fg),
  XtRString,		/* cast discards qualifiers... */
  (XtPointer) "Black"	/* initialization discards qualifiers... */
} };

XrmOptionDescRec mf_optiondesclist[] = { {
  "-width",		/* initialization discards qualifiers... */
  "width",		/* initialization discards qualifiers... */
  XrmoptionSepArg,
  (XPointer) NULL
}, {
  "-fg",		/* initialization discards qualifiers... */
  "foreground",		/* initialization discards qualifiers... */
  XrmoptionSepArg,
  (XPointer) NULL
} };



_______________________________________________
xorg mailing list
xorg@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/xorg

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic