Daniel Keep wrote:

Robert Jacques wrote:
On Tue, 22 Sep 2009 07:09:09 -0400, bearophile
<bearophileh...@lycos.com> wrote:
Robert Jacques:
[snip]
Also, another issue for game/graphic/robotic programmers is the
ability to
return fixed length arrays from functions. Though struct wrappers
mitigates this.
Why doesn't D allow to return fixed-sized arrays from functions? It's
a basic feature that I can find useful in many situations, it looks
more useful than most of the last features implemented in D2.

Bye,
bearophile
Well, fixed length arrays are an implicit/explicit pointer to some
(stack/heap) allocated memory. So returning a fixed length array usually
means returning a pointer to now invalid stack memory. Allowing
fixed-length arrays to be returned by value would be nice, but basically
means the compiler is wrapping the array in a struct, which is easy
enough to do yourself. Using wrappers also avoids the breaking the
logical semantics of arrays (i.e. pass by reference).

The problem is that currently you have a class of types which can be
passed as arguments but cannot be returned.

For example, Tango's Variant has this horrible hack where the ACTUAL
definition of Variant.get is:

    returnT!(S) get(S)();

where you have:

    template returnT(T)
    {
        static if( isStaticArrayType!(T) )
            alias typeof(T.dup) returnT;
        else
            alias T returnT;
    }

I can't recall the number of times this stupid hole in the language has
bitten me.  As for safety concerns, it's really no different to allowing
people to return delegates.  Not a very good reason, but I *REALLY* hate
having to special-case static arrays.
P.S. And another thing while I'm at it: why can't we declare void
variables?  This is another thing that really complicates generic code.

Why would you declare void variables? The point of declaring typed variables is to know what kind of storage to use, void means no storage at all. The only time I use void in variable types is for void* and void[] (which really is just a void* with a length).

In fact, every single scope has an infinity of void variables, you just don't need to explicitly declare them :)

'void foo;' is the same semantically as ''.

Reply via email to