A while ago, somebody pointed out that structures with array members don't compile properly on Verrazano. <br>
In looking at the issue, I realized that arrays are something of a special case in C-FFI, as they are morally <br>
type-specifiers in defcstruct declarations, but do not have underlying types. Therefore, I propose a new C-FFI<br>
declaration:<br>
<br>
(defcarray <foreign-type-name> <base-type> <length>)<br>
<br>
eg:<br>
<br>
int[5] -> (defcarray int-array :int 5)<br>
<br>
An explicit nil for the <length> argument would be equivalent to:<br>
<br>
(define-foreign-type int-array () ':pointer)<br>
<br>
All array types would be passed as :pointer under the hood, just like structure types.<br>
<br>
Philosophically, it might be undesirable to add array types in order to keep with the minimally-typed design<br>
of C-FFI. However, arrays, from the point of view of C semantics, are much more similar to structures than<br>
to pointers. Indeed, in the C machine model, a structure is little more than a hetrogenous array. Thus, the<br>
treatment of arrays versus structures in the C-FFI API presents something of an inconsistency, as:<br>
<br>
(defcstruct foo (a1 :int) (a2 :int))<br>
<br>
(define-foreign-type bar () 'foo)<br>
<br>
(defcstruct baz (q bar))<br>
<br>
is perfectly legal code, while:<br>
<br>
(defcarray foo :int 2)<br>
<br>
(define-foreign-type bar () 'foo)<br>
<br>
(defcstruct baz (q bar))<br>
<br>
is unrepresentable. <br>
<br>
This issue makes C-FFI somewhat incongruous with C, because in C, a structure field as a name and a type,<br>
with array's being incorporated into the type system, while in C-FFI, a structure field has a name, a type,<br>
and an optional length, with no explicit array type. Moreover, since arrays are not types, the usual type<br>
machinery that can be used on array types in C header files must be translated into other things in C-FFI<br>
declaration files. <br>
<br>
Now, there is a somewhat selfish undertone to this proposal, as the lack of array types in C-FFI necessitates<br>
a rather ugly special case in Verrazano's C-FFI backend. However, I believe that an array type would be<br>
an improvement for hand-made C-FFI declarations as well, specifically for cases where an array type<br>
is not specified directly in a structure, but used via typedef in a structure.<br>
<br>
Sincerely,<br>
Rayiner Hashem<br>
<br>