[Issue 1869] Semantically returning an array from a funciton is difficult

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 26 11:09:19 PST 2008


http://d.puremagic.com/issues/show_bug.cgi?id=1869


andrei at metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement




------- Comment #18 from andrei at metalanguage.com  2008-02-26 13:09 -------
(In reply to comment #17)
> are you talking C or D?

Both.

> I could have sworn that in C a "pointer to a fixed size
> array" (e.i. double indirection) was written as "int[4]*". If it isn't, how is
> it written?

It is written like that, and there is no double indirection.

> Oh. I think I just figured it out!:
> 
> int[4] a;
> int[4]* i = &a;
> 
> i points to the same point as a but has a different type *i is the same pointer
> as i but with the type of a and **i is the content.

That is correct.

> OK what I want to do is return *(&a), a type that is the same as "a" but is
> mutable. 

You'd need to return a reference to a fixed-size array, which in C does not
exist, in C++ is spelled int[4]&, and in D is spelled ref int[4] but so far
only applies to function arguments. 

Note that neither would be mutable, so you seem to want something that is
physically possible but can't be expressed in either of the three languages.

I'm keeping this bug report as a request for returning arrays by value, but I
guess it's duplicated with a couple others.


-- 



More information about the Digitalmars-d-bugs mailing list