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

Damian McGuckin damianm at esi.com.au
Wed Feb 19 10:32:26 PST 2020


On Wed, 19 Feb 2020, Rajan Bhakta wrote:

> I think the point of the example was explicitly to say why we don't have
> wide strfromd functions, so it really makes sense to keep strfromd there.

Agreed.

Note that Mike is correct in that C2X explicitly says that the string 's'
will NOT be NUL ('\0') terminated if

 	n < nc

That makes 'strfromd' a very unsafe routine and not one I intend to use.
But that is beside the point in this example.

Whether the standard should even have such a routine, or be promoting its 
use, is another question, but one that is sadly out of scope for the CFP.
I would have made 'strfromd' truncate and store only 'n-1' characters but 
we cannot change history.

> // convert d to single-byte character string s
> char s[n];

Should we add here:

// Note that 's' is a VLA (Variable Length Array)

> int nc = strfromd(s, n, ?%g?, d);
> // convert s (regarded as a multi-byte character
> // string) to wide string ws
> wchar_t ws[n];
> (void)mbstowcs(ws, s, n);

I think the use of a VLAs makes it more readable. I like VLAs.

Regards - Damian

Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer


More information about the Cfp-interest mailing list