Small Vectors Proposal

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Thu Feb 1 09:43:44 PST 2007


Oskar Linde wrote:
> The C (and D) static array has always been an odd type. It is not 
> assignable, but is passed by reference to functions. You can not return 
> static arrays from functions. Template libraries like std.bind have to 
> add lots of extra code to special case the static arrays. Structs 
> containing static arrays behave differently than static arrays 
> themselves. Also, in D, the static array is the only type where 
> typeof(T.init) != T.
> 
> If static arrays became a value type, all irregularities could disappear.

But then people will complain about the inconsistency between static 
arrays and dynamic arrays. Why some are passed by value and others are 
passed by reference?

> The only place this change would make any difference for old code is 
> where static arrays are passed as function parameters. I believe the 
> amount of code containing functions with static array arguments is very 
> small in D. In fact, only two Phobos modules contain such functions 
> (std.utf and std.md5). Converting those functions would be trivial: The 
> by ref behavior would be attainable with the inout and out parameter 
> types that today are forbidden for static arrays.

Probably things could be made to work; I personally am unclear on what's 
the most self-consistent set of rules.


Andrei



More information about the Digitalmars-d mailing list