Mail Archives: djgpp-workers/2002/05/31/09:02:37
Martin Stromberg wrote:
>
> Richard's mail dated Sun, 26 May 2002 17:00:53 +0100:
> tests/libc/go32/signals.c: The following line:
>
> urand = ((double)rand()) / RAND_MAX;
>
> gives this warning:
>
> gcc @../../gcc.opt -I. -I- -I../../../include -pg -c signals.c
> cc1.exe: warnings being treated as errors
> signals.c: In function `int_handler':
> signals.c:23: warning: cast does not match function type
>
... snip ...
>
> But, surely this is another useless one. When did casting from int to
> double become a non-matching type? C is defined to convert integer
> types to floating point types if the expression contains a mix. (An
> assignment is an expression.) In this case we explicitly want to
> convert to double. How to do that? Umm... Let's see... Perhaps we
> should cast it?!
It converts a double expression to int (if urand is integral).
I think you have a valid complaint about the actual warning text,
but the assignment is losing information. Once more, in general I
would prefer to be warned. So I think the solution here IS to
cast the result. We really don't want the fractional part :-)
--
Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT worldnet DOT att DOT net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
- Raw text -