Mail Archives: djgpp/2000/04/23/11:45:48
kalyniuk AT telusplanet DOT net wrote:
>However, the only change I made was to
>change the variable 'bore' from an int to a float. I would have
>thought that the compiler or linker should have thrown up an error or
>warning or something and that my program should have at least shown a
>garbage value (I did use printf to debug) returned from the function
>rather than just ignoring it and leaving it at zero.
If I understand what you did correctly, here's what happened:
Your prototype said that the function expected an int, when in fact
it expected a float. You passed it a float in the interval (0,1).
Since the compiler thought it was supposed to be an int it converted
it to an int, namely 0 (since it rounds towards 0). No warning is
given, because float-to-int conversion is entirely normal, specified
by the ANSI standard, etc. (Note, however, that gcc _will_ warn you
about such implicit conversion if you use the -Wconversion option.)
The function was expecting a float, but a 0 int and a 0 float have
exactly the same representation (four 0 bytes), so it interpreted
the parameter as 0 anyway.
S.
- Raw text -