Argumnentation against external function operator overloading is unconvincing

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 25 14:47:59 PDT 2016


On 9/25/2016 6:45 AM, Andrei Alexandrescu wrote:
> Yah, it comes as a surprise to many that static arrays are more akin to structs
> than to arrays. They really are records that happen to have several elements of
> the same type. Providing indexing for them is a convenience that somewhat adds
> to the confusion, and converting to dynamic arrays is unsafe because it
> essentially escapes the innards of the struct. Statically-sized arrays are odd,
> that's for sure, and that's the case in C and C++ as well.

I'd like to emphasize that this is an important insight. A static array is 
semantically equivalent to a struct with fields of all the same type, and the 
fields can be accessed by index rather than field name. This insight has driven 
some simplifying assumptions internal to how the compiler is implemented, as 
well as the specification for how things work (like passing a static array as a 
function parameter works like passing a struct).

Another simplifying insight is that a struct is a tuple of fields. I tried to 
generalize this by having the arguments to a function be a tuple as well, but 
ran afoul of the ABI for calling conventions, argghh. It would really be awesome 
to have tuples, structs, static arrays, and function argument lists be literally 
the same thing, but sadly that does not seem practical at the moment.


More information about the Digitalmars-d mailing list