inout/out static array parameter

Regan Heath regan at netwin.co.nz
Wed Feb 22 02:27:37 PST 2006


On Wed, 22 Feb 2006 23:05:37 +1300, Regan Heath <regan at netwin.co.nz> wrote:
> So as not to confuse things I'm using the word "variable" to describe  
> 'a' and "parameter" to describe 'b' below.
>
> void function(inout int[10] b) {}
> int[10] a;
> function(a);
>
> What I believe 'inout' does is alias the variable with the parameter. In  
> the case of an array reference <var> is an array reference and the  
> parameter 'b' is therefore simply another name for the same array  
> reference variable 'a'. Modifying the value of 'b' modifies the value of  
> 'a' (and vice-versa. I wonder if I can proove this by using a thread to  
> modify the variable...)

No threads required to proove aliasing.

void foo(inout int a) { printf("addr(a)=0x%08x\n",&a); }
void main() {
	int i;
	printf("addr(i)=0x%08x\n",&i);
	foo(i);
}

Output:
addr(i)=0x0012ff34
addr(a)=0x0012ff34

'i' and 'a' are the same int. 'a' is an alias for 'i'.

Regan



More information about the Digitalmars-d mailing list