Closed porky11 closed 6 years ago
On Fri, Sep 16, 2016 at 09:31:23AM -0700, Fabio Krapohl wrote:
Could array-references be function parameters?
Yep, that this isn't supported is just an oversight, and will be fixed.
And why can't arrays be function parameters, structs containing arrays can (like the array concept type).
I wanted to retain C's behaviour for passing arrays to functions, where the array degrades to a pointer to the first element. Given that, having array parameters that are functionally equivalent to pointers is redundant and confusing (see e.g. https://lkml.org/lkml/2015/9/3/428). This doesn't affect arrays that appear inside structs.
Even in this case, arrays are not allowed as parameters
(def-variant vec ((vec2 ((value (array-of 2 float))))
(vec3 ((value (array-of 3 float))))
(vec4 ((value (array-of 4 float))))))
Array references are now supported as function parameters. With variants, though, arrays aren't allowed for a variant's parameters because those parameters are used to form the constructor. There aren't good ways to handle this: marking all constructor parameters as (ref (const ...))
would be inefficient for primitive types, and relying on PreferRefs
doesn't work because the relevant concept-instantiation code has similar problems with array parameters. I think using Array
concept types instead of primitive arrays is the better option here.
Could array-references be function parameters? And why can't arrays be function parameters, structs containing arrays can (like the array concept type). should I use the array concept type instead of arrays?