On Sat, 24 Dec 2011 16:46:18 -0000, RenatoL <[email protected]> wrote:

snippet:


int[] arr1 = [1,2,3,4,5];
int[5] arr2 = [1,2,3,4,5];
writeln(arr1.sizeof);
writeln(arr2.sizeof);

Output:
8
20

"0 is ok to me but why "8"??

It's a quirk of D that int[] is a reference type, so you get the size of the reference (as My Anonymous said, a length and pointer) whereas int[5] is a value type, so you get the size of the value.

It's the same as the following C..

int *arr1;
int arr2[5];

printf("%d\n", sizeof(arr1));
printf("%d\n", sizeof(arr2));

R

--
Using Opera's revolutionary email client: http://www.opera.com/mail/

Reply via email to