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).