Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider not using _ecvt_s #423

Closed
alabuzhev opened this issue Nov 13, 2016 · 5 comments
Closed

Consider not using _ecvt_s #423

alabuzhev opened this issue Nov 13, 2016 · 5 comments

Comments

@alabuzhev
Copy link
Contributor

alabuzhev commented Nov 13, 2016

  • "The procedure entry point _ecvt_s could not be located in the dynamic link library msvcrt.dll"

This happens on Windows XP if compiled with MinGW, as XP's msvcrt.dll is too old and doesn't include that function, and MinGW doesn't use the static runtime library for copyright reasons.

_ecvt_s is used in implementation of bool isnegative(double x) ("Portable version of signbit").
Probably it's better to just use signbit if it's available. MinGW defines this macro in math.h.

@vitaut
Copy link
Contributor

vitaut commented Nov 13, 2016

isnegative already uses signbit by default and I'd expect the call to _ecvt_s to be optimized away if signbit is available. Do you get this error when compiling without optimizations?

@alabuzhev
Copy link
Contributor Author

http://www.cplusplus.com/reference/cmath/signbit/

In C, this is implemented as a macro that returns an int value. The type of x shall be float, double or long double
In C++, it is implemented with function overloads for each floating-point type, each returning a bool value.

So, if (const_check(sizeof(signbit(x)) == sizeof(int))) is actually if (false).

I compile with -O3, so I presume it will be optimised away indeed, just not the branch you expect.

@vitaut
Copy link
Contributor

vitaut commented Nov 13, 2016

Good catch. Does changing

    if (const_check(sizeof(signbit(x)) == sizeof(int)))

to

    if (const_check(sizeof(signbit(x)) == sizeof(int)) || const_check(sizeof(signbit(x)) == sizeof(bool)))

solve the problem?

@alabuzhev
Copy link
Contributor Author

Yes, with that change I can't find any traces of _ecvt_s in the binary and it works.

vitaut added a commit that referenced this issue Nov 15, 2016
@vitaut
Copy link
Contributor

vitaut commented Nov 15, 2016

Fixed in def6874.

@vitaut vitaut closed this as completed Nov 15, 2016
@gabime gabime mentioned this issue May 7, 2017
foonathan pushed a commit that referenced this issue Jun 8, 2017
(cherry picked from commit def6874)
vitaut added a commit that referenced this issue Jan 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants