This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: warning: assignment to `int' from `double'
- From: "Ralf W. Grosse-Kunstleve" <rwgk at cci dot lbl dot gov>
- To: gcc at gcc dot gnu dot org
- Cc: neil at daikokuya dot demon dot co dot uk, rwgk at boa dot lbl dot gov
- Date: Wed, 27 Feb 2002 11:25:15 -0800 (PST)
- Subject: Re: warning: assignment to `int' from `double'
Neil Booth wrote:
> Ralf W. Grosse-Kunstleve wrote:-
>
> > The following code generates warnings with gcc 3.0.3:
> >
> > int main()
> > {
> > int i;
> > double d;
> > i = 0;
> > i += d;
> > return 0;
> > }
> >
> > g++ -g z.cpp -o z
> >
> > z.cpp: In function `int main()':
> > z.cpp:6: warning: assignment to `int' from `double'
> > z.cpp:6: warning: argument to `int' from `double'
> >
> > Is it possible to suppress this warning without resorting to -w?
>
> Have you tried a cast?
In my application a cast is not an option. I am overloading
operator+= etc. for operations on arrays. The array
element types can be custom types with overloaded
operators. Any cast burried in the array operator+= would
interfer with the semantics of the overloaded custom
operators.
gcc 3.0.x (incl. 3.0.4) is the only compiler that issues
the warning above. (I am also using various EDG derivatives
and Codewarrior.)
Thanks,
Ralf