This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

hide/turn off -Wcast-qual within source code



I tried to compile a Motif program of mine with `-Wcast-qual' only to find
out that gcc 3.01 warned me about cast discarding qualifiers every time I
tried to use Motif string starting with `XmN'.  I then looked at Motif
headers in my SGI and I saw that all the strings starting with `XmN' did
contain casts from `const char*' to plain `char*' so the warnings
generated by `-Wcast-qual' were correct but there was nothing I could do
to fix them.

Is it possible to turn off or hide warnings generated by `-Wcast-qual'
within source code for a short while so that I could still use
`-Wcast-qual' without generating lots of warnings?

Toni Ronkko

This is a small piece of my program to demonstrate the problem:

#include <Xm/Protocols.h>
#include <GL/GLwMDrawA.h>
int main (void) {
  Widget gl_canvas; 
  gl_canvas = XtVaCreateManagedWidget(
      "canvas",
      glwMDrawingAreaWidgetClass, NULL,
      XmNtranslations, NULL,
      XmNwidth,  100,
      XmNheight, 100,
      NULL);
  return 0;
}

Compiling the program above with `g++ -Wcast-qual -c x.cpp' gives me
these warnings:

x.cpp: In function `int main()':
x.cpp:8: warning: cast from `const char*' to `char*' discards qualifiers from 
   pointer target type
x.cpp:9: warning: cast from `const char*' to `char*' discards qualifiers from 
   pointer target type
x.cpp:10: warning: cast from `const char*' to `char*' discards qualifiers from 
   pointer target type

In system headers `XmNtranslations' is defined as:

#define XmNtranslations  XtNtranslations
#define XtNtranslations  ((char*)&XtStrings[802])
extern const char XtStrings[];



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]