delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/05/31/09:02:37

Message-ID: <3CF7578A.2C2ADFE1@yahoo.com>
Date: Fri, 31 May 2002 06:59:22 -0400
From: CBFalconer <cbfalconer AT yahoo DOT com>
Organization: Ched Research
X-Mailer: Mozilla 4.75 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: Patches for building with gcc 3.1 - tests chunk
References: <200205310919 DOT LAA13003 AT lws256 DOT lu DOT erisoft DOT se>
Reply-To: djgpp-workers AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019