Skip to content

Standard library atof is unable to parse nan. Use ucrtbase.dll instead of msvcrt.dll. #98

@MarekKnapek

Description

@MarekKnapek

Steps to reproduce:

  • Write small test program in the C programming language.
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
	double dbl;

	dbl = atof("nan");
	if(dbl != dbl)
	{
		puts("gud");
	}
	else
	{
		puts("bad");
	}
}
  • Compile the program using latest x64 version of w64devkit. gcc atof.c
  • Run the program. ./a.exe

Expected result:

  • gud

Actual result:

  • bad

Repeat this experiment with the MSVC and cl.exe C compiler and the result is as expected.

The reason for this bad behavior is that the w64devkit is using the msvcrt.dll C run-time library as its libc. I believe that this library is quite old, unmaintained and buggy. Only god knows how many other issues is waiting for us inside this library. Especially related to new functionality added in later C standards. It is sad, that the gcc is able to compile newer C but is held back by old libc.

Thus, in this issue, I'm suggesting to replace dependency on msvcrt.dll by dependency on ucrtbase.dll.

This library is considered as part of Windows since Windows 10 and can be installed by Windows Update on Windows XP and later. So there should be no downsides by changing this dependency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions