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 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

This comment has been minimized.

Copy link
Contributor

@vitaut 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

This comment has been minimized.

Copy link
Contributor Author

@alabuzhev alabuzhev commented Nov 13, 2016

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

This comment has been minimized.

Copy link
Contributor

@vitaut 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

This comment has been minimized.

Copy link
Contributor Author

@alabuzhev alabuzhev commented Nov 13, 2016

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

This comment has been minimized.

Copy link
Contributor

@vitaut vitaut commented Nov 15, 2016

Fixed in def6874.

@vitaut vitaut closed this Nov 15, 2016
@gabime gabime mentioned this issue May 7, 2017
foonathan added 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
Projects
None yet
2 participants
You can’t perform that action at this time.