On Tue, 1 Apr 2003, Jennifer King wrote:
> Sheesh, a new record for me.. posting 2 msgs looking for help in the same
> week! What's this world coming to? Maybe I'm just frying too many brain
> cells between mud code and work code...
>
> Anyways.. Using gcc with -Wcast-qual, -Wcast-align, and other C flags,
> Rom2.4b6 and OLC2.01, I still have the following warnings remaining:
> olc_act.c:4080: warning: cast discards qualifiers from pointer target type
> olc_act.c:4775: warning: cast discards qualifiers from pointer target type
> olc_act.c:4780: warning: cast discards qualifiers from pointer target type
> screen.c:592: warning: cast discards qualifiers from pointer target type
>
> I can kill all 4 of those out by changing ED_FUN & ED_FUN_DEC from:
> typedef bool ED_FUN args( ( char *, CHAR_DATA *, char *, void *,
> const void * ) );
> #define ED_FUN_DEC(blah) bool blah ( char * n_fun, CHAR_DATA *ch, char
> *argument, void *arg, const void *par )
>
> To:
> typedef bool ED_FUN args( ( char *, CHAR_DATA *, char *, void *,
> void * ) );
> #define ED_FUN_DEC(blah) bool blah ( char *n_fun, CHAR_DATA *ch, char
> *argument, void *arg, void *par )
>
> However, when I do this, I open up new warnings in olc.c (multiples, but
> here's one):
> olc.c:1538: warning: passing arg 5 of pointer to function discards
> qualifiers from pointer target type
> Now, if I remove the 'const' from olc_comm_type, I open up another set
> of problemson the the lines from the table (including the one I've given
> as an example)
> olc.c:56: warning: initialization discards qualifiers from pointer target type
You're going the wrong way. Going through and removing the consts will
fix your warnings, but it works against the point of having the const
there in the first place.
It looks like you've figured out what the problem is: going from a
const pointer to a non-const pointer. But you're working backwards.
Instead of removing the const from the original pointer, and working
backwards from there, you should be going the other way. Go to the
lines causing the original warnings, and add const to those pointers.
For example:
ED_FUN_DEC(my_function)
{
char * x;
x = par;
}
would give you the errors you're seeing. Changing to something like
const char * x;
would fix the problem. Of course, your pointers may be different
types than char *, but the same principle applies.
Fixing those specific lines may cause more warnings, similar to what
you're seeing when taking the const off. Just work through them
until you fix them all.
Dennis