Tuple DIP - tuple unification with arrays and structs

Walter Bright newshound2 at digitalmars.com
Mon Jan 15 23:11:46 UTC 2018


On 1/14/2018 6:55 AM, Q. Schroll wrote:
> How is (1, 2) different from [1, 2] (static array)?
It's a very good question. It's corollary is how is (1, 2) different from

    struct S { int a, b; }

It does turn out that int[2] is structurally (!) the same as struct S. This is a 
property I've taken some pains to ensure stays valid, and it has turned out to 
be nicely useful.

But consider:

    S foo(char a, char b);

    t = ('a', 'b');
    foo(t);      // equivalent to foo('a', 'b')

That works. But:

    S s = {'a', 'b' };
    foo(s);      // Does not work

It does not work is because s as a parameter has a distinctly different ABI than 
(char, char). The former consumes an int sized parameter, the latter two int 
sized parameters. A similar issue exists with the return value.

So far, the issue of unification of tuples with arrays (and structs) has 
defeated me because of the fundamental structural differences in the ABI which 
we are stuck with.


More information about the Digitalmars-d mailing list