Re: Converting double to widestring
On Thu, 27 Mar 2008 16:49:25 +0100, "Alf P. Steinbach" <alfps@start.no>
wrote:
Although it is what's expected and natural, that doesn't seem to be documented.
Indeed. The TLS usage is to be expected, since this is what MS did for
functions which use static buffers perhaps 15 years ago when they created
the MT libraries, and it's easily verified by examining the source code.
E.g., the documentation of strtok says "calling this function simultaneously
from multiple threads does not have undesirable effects", which presumably
refers to multiple threads when using the multi-threaded CRT, but the
documentation of _ecvt, in my old MSDN lib, doesn't mention any such feature.
However, checking the source code can be an alternative to thorough testing.
I don't know that I would feel too comfortable in establishing the thread
safety of an opaque function by "thorough testing".
And the source code indicates that also _ecvt uses TLS (via internal function
_fpcvt). But anyway, one is then back to relying on undocumented functionality.
I know it's undocumented; I resisted the temptation to comment that while
this fact isn't mentioned explicitly, at least we're told, "This function
is deprecated because a more secure version is available; see _ecvt_s". :)
The bottom line is that if you program only to what's documented in MSDN,
you won't get very far. You won't be able to write MT programs, period,
because AFAIK, MS has yet to define a MT programming model, as POSIX did
10-15 years ago. That said, everyone knows that the same memory visibility
rules apply to things like mutex usage. MSDN is nowhere near as rigorous
as, say, the C++ standard, which has its own ambiguities and omissions. Of
course, you have to be able to investigate and judge what you can and can't
rely on.
More undocumented stuff: the buffer size is
# define _CVTBUFSIZE (309+40)
which seems to allow for largest double value with about 37 decimals for _fcvt.
I'm not sure where you get 37 decimals, but anyway, the second one is
actually documented, nowadays at least:
http://msdn2.microsoft.com/en-us/library/ex8sf9x0(VS.80).aspx
<q>
The total number of digits returned by _fcvt will not exceed _CVTBUFSIZE
</q>
--
Doug Harrison
Visual C++ MVP