On 2012-12-14 14:28:14 +1100, Cameron Simpson wrote:
> On 09Sep2012 20:00, Andrew Gaul <and...@gaul.org> wrote:
> | -          /* suppress GCC aliasing warning */
> | -     imap_free_header_data ((void**) (void*) &h.data);
> 
> Pardon my ignorance, but what is (was?) the use of a cast like:
> 
>   (void**) (void*)
> 
> A cast of a typed pointer to (void *) when handing it to something
> generic like free() I understand, but the above confuses me. I don't
> expect C to confuse me.

I suppose that the (void**) was necessary to have the correct type
(this is needed when compiling with a C++ compiler such as g++),
and (void*) to avoid the GCC aliasing warning (but this was really
dangerous, because if there is an aliasing problem, wrong code can
be generated).

In general, casting a pointer type to another pointer type (except
with things like char * and void *) is dangerous, because it may
be the source of aliasing problem. See the ISO C standard for more
details.

-- 
Vincent Lefèvre <vinc...@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Reply via email to