[Cfp-interest 1506] Re: AI item to submit proposal about why no wide string strfrom functions

Fred J. Tydeman tydeman at tybor.com
Wed Feb 19 13:27:53 PST 2020


On Thu, 20 Feb 2020 07:38:27 +1100 (AEDT) Damian McGuckin wrote:
>
>
>Hi Fred,
>
>On Wed, 19 Feb 2020, Fred J. Tydeman wrote:
>
>>On Thu, 20 Feb 2020 05:32:26 +1100 (AEDT) Damian McGuckin wrote:
>>>
>>>Note that Mike is correct in that C2X explicitly says that the string 's'
>>>will NOT be NUL ('\0') terminated if
>>>
>>>      n < nc
>>
>>Where are you seeing that?
>
>I was quoting from the last sentence of C2X Draft in the References section on the Wiki, N2454.pdf. See the full quote at 
>the very bottom of this email.
>
>..... the null-terminated output has been completely written if and only if the returned value is less than 'n'.
>
>>7.22.1.3 in returns has: ;... null-terminated output ...
>
>See the full text.
>>
>>7.21.6.5 has: ... output characters beyond the n-1st are discarded rather than being written to the array, and a null 
>character is written at the end of the characters actually written into the array.
>
>You are quoting from snprintf, not strfromd.

Agreed.  Because strfrom* say that they are equivalent to snprintf().

>This is what I would expect the behaviour of strfromd would/should be. But instead it is different. Excuse my cutting and 
>pasting below.

It is not different.

>In 7.22.1.3
>
>Returns
>
>The strfromd, strfromf, and strfroml functions return the number of characters that would have been written had n been 
>sufficiently large, not counting the terminating null character. Thus, the null-terminated output has been completely written if 
>and only if the returned value is less than n.

By the way, those sentence are in both strfrom* and snprintf..

I can see that can be read in two different ways.  Better would be:
The output is null-terminated.  The output is completely written 
if and only if the returned value is less than n.

That says that:
   the output is null-terminated.  
   it is complete if its length is less than n.

If the complete length is greater or equal to n,
then the null-terminated string is missing the 
characters on the right end of the number.


---
Fred J. Tydeman        Tydeman Consulting
tydeman at tybor.com      Testing, numerics, programming
+1 (702) 608-6093      Vice-chair of PL22.11 (ANSI "C")
Sample C99+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.



More information about the Cfp-interest mailing list