NO

Author Topic: How to ecvt?  (Read 3602 times)

akko

  • Guest
How to ecvt?
« on: April 21, 2007, 02:33:33 PM »
Sadly, ecvt does not work, despite it is declared in the msvcrt.lib of PellesC.

There is a small thread in the "experts" section of the forum, concerning some remedy actions. However none of ideas expressed there are working.

The following proggie works with all different C compilers on my computer,  but not with PellesC:

/* Cheap ecvt test */
#include <stdio.h>
#include <stdlib.h>
void main(void)
{  int a, b;
   char * conv = ecvt(9e0,20,&a,&b);
   printf("\nECVT Test: %f -> %s, %d, %d ",9e0,conv,a,b);
}

It should print:
ECVT Test: 9.000000 -> 90000000000000000000, 1, 0

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: How to ecvt?
« Reply #1 on: April 21, 2007, 03:45:00 PM »
Missing function prototype.

http://msdn2.microsoft.com/en-us/library/z4s4541k(VS.80).aspx

Code: [Select]
/* Cheap ecvt test */
#include <stdio.h>
#include <stdlib.h>

char *_ecvt(double value, int ndigit, int *decpt, int *sign);
#pragma lib "msvcrt.lib"

void main(void)
{  int a, b;
   char * conv = _ecvt(9e0,20,&a,&b);
   printf("\nECVT Test: %f -> %s, %d, %d\n",9e0,conv,a,b);
}

/*
It should print:
ECVT Test: 9.000000 -> 90000000000000000000, 1, 0
*/
May the source be with you

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: How to ecvt?
« Reply #2 on: April 21, 2007, 04:47:07 PM »
ecvt is not part of standard C, and Posix flag it as 'legacy' (The sprintf() function is preferred over ecvt, fcvt, gcvt). I see no reason in the world to support it...
/Pelle

akko

  • Guest
Re: How to ecvt?
« Reply #3 on: April 22, 2007, 09:29:36 PM »
Thanks Timo, that works.
However I get the warning
POLINK: warning: Multiple '.rdata' sections found with different flags (0x40000040 and 0xc0000040).

Pelle:
Of course everything is up to you. However please think of those who want to use good valid legacy code.
And it is NOT trivial to express ecvt by snprintf.
IMHO ony should be able to use all routines in msvcrt.lib. They come for free, don't they?
You are already supporting io.h which contains mostly POSIX and not C99 definitions.