Return type

I

Ioannis Vranos

Brandon said:
It's possible I'm missing something, but I really don't see the utility of
declaring an array by value when you would have to pass it around by handle
anyways. The complaint really comes down to whether there is a caret in the
written declaration or not -- there's no semantic advantages.



It would also mean deterministic destruction of contained objects. Also
it could help to think of it as an object with no copy constructor and
assignment operator (in ISO C++ by making them private members).


We extended the syntax to allow aggregate initialization of CLR arrays. CLR
arrays are always passed by handle. In the same regard, operators work on
handles for the exact same reason. Rather than force syntax to match
automatic storage semantics (even though it doesn't make sense), we took the
approach that it should work for garbage-collection semantics.


Another way would be to make it with built in array semantics, with the
name of the array to be resolved as a handle to the first object in the
array, or a handle in general.


However the template object in the stack makes more sense.



In summary an example:



void somefunc(array<int> ^h)
{
// ...
}


// ...

array<int> ar={1,2,3,4,5};

// ...


somefunc(%ar);


// ...

// ar is destroyed at the end of its scope.




There is a big difference between the capabilities of a valarray verses an
array. First, a CLR array today (i.e. the System::Array type) does not have
copy semantics, does not physically embed in types, has the capability of
being jagged, etc. Valarrays would have different properties. I can
understand the desire to make all types super flexible, but of course that
results in less useful types in the end. Engineering types for specific
purposes with good capabilities is the right thing for language designers
and library providers to do. Choosing between a selection of types is the
job of a good developer.


Yes I am not asking about a built in valarray, Tomas mentioned it. I am
talking about the current .NET array.






Best regards,

Ioannis Vranos
 
I

Ioannis Vranos

Fixed:


Ioannis said:
Yes I am not asking about a built in valarray,
you

mentioned it. I am talking about the current .NET array.






Best regards,

Ioannis Vranos
 
B

Brandon Bray [MSFT]

Ioannis said:
It would also mean deterministic destruction of contained objects. Also
it could help to think of it as an object with no copy constructor and
assignment operator (in ISO C++ by making them private members).

As arrays do not have destructors, there would be nothing to instigate a
tear down of each element. If we were to do that for arrays declared on the
stack only, then an inconsistency arrises where the stack based arrays have
different destruction semantics than a garbage collected arrays.

As things are today, an array is very much like an object with a private
destructor. Objects with private destructors cannot be allocated on the
stack.
Another way would be to make it with built in array semantics, with the
name of the array to be resolved as a handle to the first object in the
array, or a handle in general.

However the template object in the stack makes more sense.

I understand the example; however, I do not understand the usefulness of the
example. Declaring an 'ar' as a handle and then never using the % operator
yields exactly the same semantics.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top