Bill Caroselli <firstname.lastname@example.org
I'm porting some QNX4 photon code. My projects with maximum warning
level set. When compiling a C++ module with maximum warnings set and
including photon/PtTree.h I get:
/usr/include/photon/PtTree.h:201: warning: cast discards qualifiers from pointer target type
This simply maintains the 'const' in the typecast. The compiler is
right and QSSL should fix their header file(s).
The compiler is right, but only in the sense that the compiler is free
to warn you about anything it wishes to. What matters is that it
doesn't refuse to compile correct code; and code that casts away the
constness of a pointer is not incorrect, even if it does it
But in this case I agree that *not* doing it is better. I'll fix it.
Is there some way that QSSL can compile all of their header files with
maximum warning levels set to find all instances where things were
But in this case, things are sufficiently typecast, as far as the
language is concerned; it's just that according to GCC's preferences,
such a typecast is suspicious enough to deserve a warning at the highest
Personally, I don't think it's a good idea to make following GCC's
preferences a policy that you have to obey at all cost. Especially if
you consider porting your code to other compilers that might have
different preferences. Of course, *we* shouldn't make that decision for
our customers; I agree that it's better if our headers don't generate
unnecessary warnings. But I would be upset if I were told that my
*code* must compile without warnings from gcc at -w9.
GCC can be really annoying when you turn the warnings too high. I
really hate how it wants you to stick superfluous parentheses and braces
everywhere. Or that when you actually do need to convert a const
pointer to a non-const pointer (in C), there's no way to do it without
getting a warning unless you do something really horrible like this:
void *p; void const *cp;
p = (void*) cp; // Warning!
memcpy( &p, &cp, sizeof(p) ); // Eeew! But no warning.