3 ms·
I think it's mostly a switching cost problem. Strings-as-char-* are part of the public APIs of damn near every C library, including the standard library, so th
by munificent 8y ago
I think it's mostly a switching cost problem.
Strings-as-char-* are part of the public APIs of damn near every C library, including the standard library, so there's no way to change that idiom without breaking the world or causing a huge migration tax. The kind of people using C are often doing so specifically because they want to avoid that kind of churn and want a maximally-stable platform, even if what it's stabilized to is sub-optimal.
- TimJYoung 8y agoYes, but none of that would need to change. I hate to keep harping on Object Pascal, but it really is a nice implementation: in OP, you can pass a string to a C API, such as the Windows APIs, like this: Result:=CreateFile(pChar(FileName), AccessMode,ShareMode,nil, OpenFlags,AttrFlags,0); where FileName is a String and pChar is the more traditional C-style pointer to an array of characters. The compiler will prevent you from passing a Unicode/Wide string to an API call that expects an ANSI string pointer, or vice-versa. So, interop with the system-level APIs of Windows or Linux is seamless and easy.
- TimJYoung 8y agoBTW, I almost forgot to mention: the String type in Object Pascal implicitly contains a NULL terminator, so the above call is zero-copy. More information: http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Internal_Data_Formats_(Delphi) http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Internal_D... under "Long String Types".