Mail Archives: djgpp/2001/02/01/20:41:17
Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk> schrieb Folgendes:
> dontmailme AT iname DOT com (Steamer) wrote:
>
> > Eli Zaretskii wrote:
>
> > > Hmm? Is this in C or in C++? I don't think you need any casts in a C
> > > program for assigning int to a double or the other way around.
> >
> > Nor do you in C++. It's strange that GCC chooses to warn about
> > this in C++ but not in C.
>
> Even stranger when you consider that it does so without even *any*
> -W... switches. Unless, that is, you are of the opinion that this is
> an "obviously dangerous conversion" - [BS; CPL3].
>
> Apart from the obvious problem that the value will be truncated to an
> integer, there is also undefined behaviour when the integer value is
> outside the range of an int. Of course, an explicit conversion says
> to gcc: Yes! I really wanted to do that, and the warning goes away:
>
> float f = 1.2;
> int i = int(f);
And what about unsigned int?
static_cast<unsigned int> (f)?
I hate C-style casts because I do not know what they do; they are a
mixture of static_cast and reinterpret_cast. So I do not like
(unsigned int) f
.
> This would surely cause problems when using a severe set of warnings,
> but everyone aims to get a clean compile with -Wall, right? ;-)
ACK. They are _warnings_ and not _errors_.
Why not suggest to the gcc maintainers that gcc should print
x.cpp:3 warning: instantiated from here
or
x.cpp:3 error: instantiated from here
instead of
x.cpp:3 instantiated from here
? The RHIDE problem would go away immediately.
--
Nuper erat medicus, nunc est vispillo, Diaulus:
Quod vispillo facit, fecerat et medicus.
- Raw text -