[dmd-beta] rvalue references

Jonathan M Davis jmdavisProg at gmx.com
Sun Apr 15 17:29:20 PDT 2012


On Sunday, April 15, 2012 09:07:03 Sean Kelly wrote:
> On Apr 13, 2012, at 1:48 PM, "Jonathan M Davis" <jmdavisProg at gmx.com> wrote:
> > On Friday, April 13, 2012 22:18:16 Don Clugston wrote:
> >> Interestingly, the ref int[3] idiom is documented as working, under
> >> 'interfacing with C'.
> >> Anything beyond that seems to be undefined.
> >> That page seems to document dynamic arrays as _not_ working --
> >> certainly as having no C equivalent.
> > 
> > Which seems really backwards considering that in both case, you'd be using
> > T* in C, and if anything, dynamic arrays are closer to that than static
> > arrays. Personally, I'd have expected arr.ptr to be required in both
> > cases.
> The problem is mostly with stuff like:
> 
> extern (C):
> alias int[2] foo;
> void fn(foo);
> 
> Now make the alias platform-dependent (as in the Posix package) and tell me
> what the prototype for fn() should be. Fortunately, static array args are
> almost nonexistent in C99 and Posix.

It was my understanding that you arrays in C are _always_ passed as a pointer 
and that even if you use [] instead of * on the parameter, it's the same as 
using * and that there was no way to specifically pass a static array 
differently from a dynamic one. But I may remember that incorrectly, since I 
almost never use static arrays.

If I'm right though, then fn will just always take an int*.

- Jonathan M Davis


More information about the dmd-beta mailing list