Re: how to cast away 'volatile'?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux