c/6980: -Wbad-function-cast gives bogus warning for (double) rand()
richdawe@bigfoot.com
richdawe@bigfoot.com
Mon Jun 10 01:56:00 GMT 2002
>Number: 6980
>Category: c
>Synopsis: -Wbad-function-cast gives bogus warning for (double) rand()
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Jun 10 01:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Richard Dawe
>Release: gcc 3.1
>Organization:
>Environment:
DJGPP ports of gcc 3.1 & binutils 2.11.2, DJGPP CVS, running on Windows 98 SE
>Description:
Here is a simple test case:
---Start program---
#include <limits.h>
#include <stdlib.h>
int
main (void)
{
double d;
d = (double) rand() / RAND_MAX;
return(EXIT_SUCCESS);
}
---End program---
I compile the program like this and get the following warnings:
bash-2.04$ gcc -Wall -Wbad-function-cast -c a.c
a.c: In function `main':
a.c:9: warning: cast does not match function type
rand is defined in <stdlib.h> like this:
int rand(void);
Since an integer can fit into a double, I don't understand why this code gives a warning. We've discussed the warning on djgpp-workers@delorie.com and most people think it's a bug.
Thank you for your time. Regards, Richard Dawe
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list