At 02:26 8/22/2002 +0200, Marcus Börger wrote:

>At 01:51 22.08.2002, Melvyn Sopacua wrote:
>>
>>Then this one is definetely not C99 compliant. Changed the test to:
>>#include <stdio.h>
>>
>>int main()
>>{
>>         char buf[5];
>>         int written;
>>
>>         written = snprintf(buf, sizeof(buf), "%f", .111);
>>         if (strcmp("0.1", buf)==0 && written == 6)
>>         {
>>                 printf("OK\n");
>>         }
>>         else
>>         {
>>                 printf("Not ok: %s (%i)\n", buf, written);
>>         }
>>}
>>
>>Result:
>>Not ok: 0.11 (5)
>
>
>How is this, did you mean 3 * '1'? The function is supposed to return the 
>number of
>characters that could have been written (excluding the terminating \0).

What it does is return the actual written characters. The terminator is not 
consistent.
0.11\0 which would be 5 characters. The result given below is 0\0 would in 
this case
be 2 characters, but 1 is returned.
(The strcmp above should of course be "0.111" - was too sleepy to notice :-).

>>Additionally - with "%.f" it rounds to integer zero.
>>
>>Result:
>>Not ok: 0 (1)
>
>A quick look in the docs says when no precision is given 6 is assumed.
>So i would expect "0.111"

Yes, when no precision is given. According to the docs, a precision 
consists of '.'
followed by p. %.f then would be either illegal, or p being NULL resolves 
to zero.

Testing with 0.999 as a value reveals, that zero is assumed for p, since 
the result
then is 1.

Met vriendelijke groeten / With kind regards,

Webmaster IDG.nl
Melvyn Sopacua


--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to