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]
Other format: [Raw text]

Re: how to cast away 'volatile'?


Jeffrey Holle wrote:
Matthew Woehlke wrote:

my_free(void*)bar);

Should be: my_free((void*)bar);

...excusing the typo. :-) The point was I have tried what you suggested (i.e. what I wrote, sans the obvious typo), and I get the same warning.


I'm attaching a file that demonstrates the problem when built with '-Wcast-qual'. Note that it builds with the warning (cast.c:8), but no errors. (Runs OK too...)

--
Matthew
Emacs is a nice OS - but it lacks a good text editor.
That's why I am using Vim.  -- Anonymous
#include <stdlib.h>
typedef volatile long atom_t, * atom_p;

void foo(atom_p bar)
{
    volatile long * tmp1 = (volatile long *)bar;
    volatile void * tmp2 = (volatile void *)tmp1;
    void * tmp3 = (void *)tmp2; /* <-- WARNING */
    free(tmp3);
}

int main()
{
    atom_p bar = malloc(sizeof(atom_t));
    foo(bar);
    return 0;
}

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