[Issue 8887] static arrays passed by value in extern C/C++ functions should not compile
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Nov 7 12:10:39 PST 2014
https://issues.dlang.org/show_bug.cgi?id=8887
--- Comment #11 from Steven Schveighoffer <schveiguy at yahoo.com> ---
The issue here is -- we use the non-mangling "feature" of C calls to override
type checking inside druntime. So even if something is extern(C) it can
actually be implemented in D. That function may never need to be called or used
in C code at all.
Why shouldn't D support ref for C? All it is doing is auto-taking the address
of the parameter, which maps perfectly to accepting a pointer or array
argument.
I think the important pieces of the C ABI to implement are where parameters go,
and the lack of name mangling. Other than that, how to pass certain types is
more fuzzy.
As another example, on a 32-bit system, C's long is 32-bit. But D's long is 64
bit. What to do here?
extern(C) foo(long x);
Clearly, it's not too important the type of x, but how big it actually is. This
leads one to simply type it as int instead, and move on. This hasn't really
caused tremendous issues or difficulties. I think really the crux of the push
for this bug is more that D2 behaves differently vs. D1 than D2 implements the
C ABI incorrectly.
Note, I remember the ref trick when we moved to passing static arrays by value,
for the system call pipe. This takes an int[2]. To switch this to a pointer not
only breaks existing code, but we lose the type requirement that it should be
exactly 2 elements wide. The ref solution worked, so we employed it, and I
think it was the right move.
--
More information about the Digitalmars-d-bugs
mailing list