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 <[email protected]>
/* 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
[email protected]
http://lists.freedesktop.org/mailman/listinfo/xorg

Reply via email to