Why don't we use the CRT functions under Windows?

Steven Schveighoffer schveiguy at gmail.com
Sun May 23 00:13:51 UTC 2021


On 5/22/21 12:25 PM, Andrei Alexandrescu wrote:
> While working with the dmd codebase 
> (https://github.com/dlang/dmd/pull/12560) I noticed that it 
> systematically shuns C runtime calls to functions such as unlink, rename 
> etc. Instead the code uses native Windows API calls (DeleteFile, MoveFile).
> 
> Spoke to Walter about it, he said the reason is mostly historical and 
> for the most part forgotten and probably obsolete - at least in the 
> past, Windows implementations of CRT was poorly done, had subtle 
> differences, and bugs.
> 
> Is that still the case? If not, we could reduce the complexity of source 
> code considerably by unifying version(Posix) and version(Windows) code.
> 

It so happens that the CRT functions for something like unlink and 
rename *are* the system calls on Unix. On windows, they are wrappers. I 
know in at least some cases Windows implements minimal features for 
their C interface, while providing full featured support with their SDK 
calls. I think druntime/phobos should focus on the minimal required 
libraries to work on the OS. Especially for things that require i/o 
handles, the C library abstraction is poor on Windows.

But this is my opinion for our standard library. For DMD though? I don't 
really care if it uses/depends on CRT. Ideally, it should have an 
abstraction layer for these things, and use whatever works.

-Steve


More information about the Digitalmars-d mailing list