Frank Heckenbach wrote:
Adriaan van Os wrote:
... snip ...
Indeed this C statement is wrong. One doesn't have to go into target specifics. The `%f' format expects an argument of type `double', as documented. Since `printf' is a varargs function, it doesn't do argument conversions (unlike Pascal's `WriteLn'), so passing any other type than `double' is wrong. So, this part of the answer is no nonsense.
: Second the following shows the correct result: : #include <stdio.h> : #include <math.h> : : int main( void ) : { : long double R; : R = sin( 1.2345); : printf( "sizeof( long double) = %d\n", sizeof( long double)); : printf( "sin( 1.2345) = %.30f = %.30f\n", (double)R, (double)R); : return 0; : }
This program is correct. However `sin' returns a `double' (this
No it isn't. sizeof returns a size_t, which is not necessarily anything like an int, and is unsigned. The result should be cast to an unsigned long (in C90) and so treated in the format specification. I believe C99 has a %zu specifier available for size_t items. Similarly %td is available for ptrdiff_t items, which are signed, and which has no bearing on the above code. -- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson