[Issue 1869] New: Semantically returning an array from a funciton is difficult
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Feb 25 13:33:22 PST 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1869
Summary: Semantically returning an array from a funciton is
difficult
Product: D
Version: 1.026
Platform: PC
OS/Version: Linux
Status: NEW
Keywords: spec
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: jason at spashett.com
It is difficult to 'return' an array from a function. Static arrays cannot be
returned, presumably because arrays are akin to full class objects. This
sometimes is a bit inconvenient when, for example one would like to assign to
a static array by calling a function.
In contrast structs can be returned from a function easily, and in fact to
return an array one can wrap it in a struct. Other ways may include the use of
boxing, or returning a dynamic array, which becomes more complicated if it is
multi-dimensional.
Currently this method seems the best solution, but requires a persistent object
allocation as opposed to using the stack (as in structs presumably):
/* Assume matrix is a class member, or static */
float[4][4] * toFloatArray4x4()
{
return &matrix;
}
float v[4][4] = *m1.toFloatArray4x4();
Obviously arrays can also be passed in as parameters, but this denies one the
functional return like semantic which can often be useful.
--
More information about the Digitalmars-d-bugs
mailing list