how to cast away 'volatile'?

Matthew Woehlke mw_triad@users.sourceforge.net
Tue Mar 13 21:33:00 GMT 2007


Matthew Woehlke wrote:
> I have a code snippet that looks roughly like this:
> 
> extern void my_free(void* ptr);
> 
> int foo()
> {
>     volatile long * bar;
>     ...
>     my_free(bar);
> }
> 
> This generates the warning 'cast discards qualifiers from pointer target 
> type' at my_free() (gcc 3.4.3). Other than disabling the flag that 
> generates the warning (in general I want these warnings!), how do I 
> suppress this? my_free is of course a free() wrapper, i.e. I don't see 
> any problems discarding the qualifier at this point. I already tried 
> this, which seems like it used to work (I am moving the code from one 
> project to another):
> 
>     my_free((void*)bar);
> 
> ...and it doesn't help.

Hmm, maybe the problem is -Wcast-qual... does that cover both implicit 
*and* explicit casts, or just explicit ones? Is there a way (like, I 
guess, const_cast in C++) to selectively disable a -Wcast-qual warning?

-- 
Matthew
HIPPOS feel unacknowledged. HIPPOS get angry.
 > PRAISE HIPPOS
HIPPOS seem somewhat placated.



More information about the Gcc-help mailing list