This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
RE: While compiling binutils-2.17, i get the error "dereferencing type-punned pointer will break strict-aliasing rules"
Hi Nick
Thanks for replying. I understand that the typecasting is proper and the code really does work. My issue is that due to this warning I cannot compile with -Werror flag. Is there a way to suppress this particular warning using #pragma etc for this particular case. I don't want to remove -Werror and compile which looks like my last option as of now.
Thanks
Mayank
-----Original Message-----
From: binutils-owner@sourceware.org [mailto:binutils-owner@sourceware.org] On Behalf Of Nick Clifton
Sent: Monday, June 18, 2007 9:12 PM
To: Mayank Kumar
Cc: binutils@sources.redhat.com
Subject: Re: While compiling binutils-2.17, i get the error "dereferencing type-punned pointer will break strict-aliasing rules"
Hi Mayank,
> (struct bfd_link_hash_entry **) &h))) -->The error points to this line in all places.
>
> The problem is that variable h is of type struct coff_link_hash_entry *, whereas the
> function pointer expects a variable of type struct bfd_link_hash_entry *.
>
> Does anybody know how to fix the above error.
This is not an error. The coff_link_hash_entry structure includes a
bfd_link_hash_entry structure as its first field. (See bfd/libcoff.h).
Hence it is OK to cast the pointer in this way.
There may be more elegant ways to handle this sort of thing, but the
code does work.
Cheers
Nick