Mail Archives: djgpp/1997/10/15/23:46:24
In article <34455CCF DOT 41C6 AT jcu DOT edu DOT au>, Oon DOT Lin AT jcu DOT edu DOT au says...
>
>Hi !
>
>I was doing a simple printf but it seems like I don't get the result I
>want...
>
>The statement was :
>
> printf("Vertical Retrace Time = %f \n", 1/70) ;
>
>
>I was careful to use '\n' to force the statement above to be printed out
>but what I got was
>
> Vertical Retrace Time = 0.000000
>
>
>Wha ???
>
>
>When I cast the calculation
>
> printf("Vertical Retrace Time = %f \n", (float)(1/70)) ;
>
>I got the result that I want....
>
>Is this a bug in GNU ??
>
No, it's a feature in C. You're dealing with a variable length, untyped,
argument list. Without the cast to ensure you get a float of the proper
type for the format string, anything can happen, and generally does, in
all C compilers.
- Raw text -