Author Topic: ecvt missing  (Read 3363 times)


  • Guest
ecvt missing
« on: March 04, 2007, 08:52:46 am »
I know ecvt et al are obsolete and "should be replaced by snprintf"
However that makes them not disappear from existing code.

What can I do?


  • Guest
ecvt missing
« Reply #1 on: March 04, 2007, 08:58:40 pm »
That function is not part of the standard C library. You can either modify the code in a thorough and sensible way, making it use snprintf() or you can write the function ecvt() yourself.

I think that ecvt() is present in glibc:

although maybe it would be difficult to single that only fragment of code out.

A very quick-and-dirty (and unreliable) implementation I've managed to code, and based on the description I've found here:

is this:

Code: [Select]

char *ecvt1(double value, int ndigit, int *decpt, int *sign) {
   static char buffer[348];
   static const int n = sizeof(buffer)/sizeof(buffer[0])-1;
   ptrdiff_t pd;
   int len;
   int zeros=0;

   if (ndigit > n) ndigit=n;

   while (value > -1.0 && value < 1.0 ) {


   if (buffer[0]=='-') {
      memmove(buffer, buffer+1, --len);
   else *sign = 0;


   if (len >= ndigit) buffer[ndigit]='\0';
   else {

   return buffer;


  • Guest
ecvt missing
« Reply #2 on: March 05, 2007, 06:02:52 pm »
I'm on Windows.
The crtdll.dll contains _ecvt.
Could one use that?


  • Guest
ecvt missing
« Reply #3 on: March 05, 2007, 06:29:44 pm »
I think it's possible as long as you have a proper prototype for ecvt() and you are able to call that function from the dll (and I think this implies modifications to your existing code).
I'm not really so much into Windows programming to tell you exactly how to proceed, but you maybe make yourself an idea reading here:

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1822
ecvt missing
« Reply #4 on: March 05, 2007, 09:52:49 pm »
use polib.exe

polib.exe /OUT:crtdll.lib crtdll.dll

or just that function

polib.exe /DEF:crtdll_ecvt.def /OUT:crtdll_ecvt.lib

Code: [Select]
LIBRARY crtdll

May the source be with you