General Category > Ideas
Array types
kyle:
Well, it depends :)
If you want to do things exactly the same way as C (conversion from array to pointer), then there isn't much you can do.
However, if you are willing to extend things a bit, then you could pass array bounds in either fat pointers, or via metadata that can be retrieved via the pointer.
Personally, I would like to be able to pass
--- Code: ---int a[14] = {0,};
foo(a);
--- End code ---
and have
--- Code: ---foo()
--- End code ---
be defined:
--- Code: ---void foo(int an_array[])
--- End code ---
And have the passed array get copied. If I want to share it, I'll explicitly pass a pointer.
Of course, if you did that, then to call C libraries, you would need to make sure that you explicitly passed a pointer to the first element of the array.
I'll think about this more... It isn't that clear.
bas:
It would indeed be nice to let caller choose calling by value (thus copy) or by reference.
External C libraries would make this decision hard indeed. It seems simple but has
many consequences as you already stated...
Navigation
[0] Message Index
[*] Previous page
Go to full version