This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: recasting an error to a warning?
- From: Matthew Woehlke <mw_triad at users dot sourceforge dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 27 Aug 2007 20:35:47 -0500
- Subject: Re: recasting an error to a warning?
- References: <6.2.5.6.2.20070815144551.01ea1a80@opnet.com>
Mark Winstead wrote:
Using gcc on a Itanium chip with Linux SUSE I get the error message (and
similar ones):
/localviews/hpc/vc/src/ace/ace_virtual.cpp:1714: error: cast from
'void*' to 'int' loses precision
I know that what is happening is a 64 bit value is being cast to a 32
bit value. The problem is I've counted 427 instances of this or a like
error. The developer's say they've made this code work on other 64 bit
platforms -- what is going on is that they took a 32 bit value and
stored it in the larger, and this is coming back down. (no, I don't know
why they did this). So it just needs a simple truncation.
Either there is a flag hidden in the makefiles that is promoting a
warning to an error here, or I hope there is a flag that casts this
error to a warning. Help?
I don't have this problem in any C++ code I maintain, but the way we
suppress the warning in C code is by Writing Good Code; IOW, make it
explicit what you are doing, like this:
int foo = (int)(long)ptr;
The cast from void* to long is usually correct (if not, replace it with
something that you erliably typedef to be 'an integer whose size ==
sizeof(void*)'). Then you can safely downcast the larger integer to a
(potentially) smaller integer (int).
--
Matthew
Microsoft: driving people fscking insane...