From: Danny S. <dan...@cl...> - 2007-07-17 21:16:48
|
Greg Chicares Wednesday, 18 July 2007 4:19 a.m. > On 2007-07-12 23:30Z, Danny Smith wrote: > > > > Recently added __mingw_snprintf and __mingw_vsnprintf work > correctly, > > per C99. > > Thanks for this. I've tested it as follows, and it looks great. > > (1) My production code has unit tests to validate snprintf(), > because msvcrt isn't the only runtime that gets it wrong (e.g., > borland has its own errors). All those tests pass now that I've > built libmingwex with CFLAGS='-DEXPORT_WEAK_SNPRINTF_ALIAS' and > (as a temporary expedient) added Weak alias support 'seems' to work most times, but I would not count on it. The PE_COFF characteristics for the weak symbol are not set correctly in object file, so it is bound to fail wih MS linker. > extern "C" int __mingw_snprintf(char *s, size_t n, const > char *fmt, ...); > #define snprintf __mingw_snprintf > to my code. I'm sure you have a much stronger testsuite already, > but it never hurts to run a few more tests. > > (2) As for speed, we don't want another "pow() is too slow" > controversy, so I ran this function a hundred times: > void time0() > { > static char buf[100] = "zzzzzzzzzzzzz"; > snprintf(buf, 12, "%11.6f", 1234.56789); > } > and found that __mingw_snprintf took 30% longer; and it took > 60% longer for this more-precise variant: > static char buf[100] = "zzzzzzzzzzzzzzzzzzzzz"; > snprintf(buf, 20, "%19.14f", 1234.5678911111111); Thanks for that. I observed similar hit from using the gdtoa float conversion routine. > That seems to be an acceptable price to pay for correctness. > OTOH, using a 'd' conversion: > static char buf[100] = "zzzzzzzzzzzzzzzzzzzzz"; > snprintf(buf, 20, "%19.14d", 1234.5678911111111); > the new code ran in 40% less time than the msvcrt version. > > So I look forward to seeing this in an official release whenever > you get around to it. If msvcrt's _snprintf() remains available > with its underscore-prefixed name, then is there any reason not > to make the C99-conformant libmingwex version the default when > the standard name snprintf() is used? > IMHO, no. Danny > -------------------------------------------------------------- > ----------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > MinGW-users mailing list > Min...@li... > > You may change your MinGW Account Options or unsubscribe at: > https://lists.sourceforge.net/lists/listinfo/mingw-users > |