On Tue, 26 Apr 2011 13:11:20 -0400, Andrej Mitrovic
<[email protected]> wrote:
On 4/26/11, Timon Gehr <[email protected]> wrote:
Isn't it dangerous to pass a D string and let the C code overwrite the
string, regardless of char* vs .ptr field?
There is a possibility for buffer overflow.
No, I mean the C function will overwrite an immutable string.
D would not allow you to pass a .ptr field of an immutable string, because
the type would be immutable(char)* and wouldn't implicitly cast to the
required char* argument. Casting, however, would mask that problem and
probably overwrite immutable data (and probably segfault on Linux).
Another example of why casting is bad.
for example, this should throw an error:
import std.stdio;
void main()
{
sprintf("buf".ptr, "%d", 12345);
}
-Steve