[Issue 1869] Semantically returning an array from a funciton is	difficult
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Mon Feb 25 23:13:00 PST 2008
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=1869
------- Comment #12 from andrei at metalanguage.com  2008-02-26 01:12 -------
(In reply to comment #11)
> traditionally arrays are worked by pointer math. While the array is a segment
> of memory, its manifestation in the code is as a pointer. So "i[2]" takes a
> pointer adds an offset of 2 and does the IO. From this "int[4]*" will be a
> pointer to something that can be used like a an array, e.i. it will be a
> pointer to a somewhat hidden pointer.
That is incorrect. There is no hidden pointer and no extra indirection. There
is a confusion somewhere along the way, so please let me give an example:
void main()
{
    int a[4];
    int[4]* b = &a;
    a[1] = 2;
    (*b)[1] = 3;
}
Say that the four ints in a start at address 1000. Then a is an immutable
pointer with value 1000. Also, b is a rebindable pointer with value 1000.
Dereferencing b takes you straight to the first element of a, not to some
hidden pointer that in turn takes you to the first element of a.
-- 
    
    
More information about the Digitalmars-d-bugs
mailing list