Mail Archives: djgpp-workers/2002/06/10/05:33:53
>Category: c
>Synopsis: -Wbad-function-cast gives bogus warning for (double) rand()
>Confidential: no
>Severity: non-critical
>Priority: medium
>Class: sw-bug
>Submitter-Id: net
>Originator: Richard Dawe
>Release: gcc 3.1
>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 AT delorie DOT com and most people think it's a bug.
Thank you for your time. Regards, Richard Dawe
>How-To-Repeat:
>Fix:
>Unformatted:
- Raw text -