← Back to context

Comment by IiydAbITMvJkqKf

4 years ago

The root cause is that argv isn't a first-class citizen like on linux, but an abstraction. The kernel only cares about a single string argument. If you use main instead of WinMain, the CRT will transform the single string into an argv for you.

Oh and cmd.exe uses a different escaping scheme than the CRT.

Microsoft is in full control of the Windows kernel, so they can make it care about whatever they want to, and one would think better argument passing would be a nice quality of life improvement. Less nonsense for developers to deal with, and less weird bugs on the platform.

  • Sure, but MS values backwards compatibility a lot.

    They aren't going to break existing API or bloat the kernel with a bunch of functions that do the same thing.

    • They can either add a new API which almost nobody would use ― because everyone already learned to use the existing one and either reused or reimplemented the MSVCRT's logic so that most of the software parse the command lines the same way; or they can literally break every single program in existence by breaking the interface of CreateProcess ― which is just as likely as Linux breaking the interface of execve(2).

      Giving CreateProcess a new flag so it would to correctly accept "path\\to\\my\\program.exe\0arg_1\0second argument\0argument with literal \" symbol" (with an implicit \0 terminating it) as lpszCmdLine is an easy part; the hard part would be forcing everyone to switch to using it.

      Also, I'm pretty certain this processing happens in the user space, and Win32 API is already bloated beyond any belief.