Changes between Initial Version and Version 1 of Arrays


Ignore:
Timestamp:
08/19/13 14:30:22 (13 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Arrays

    v1 v1  
     1= Arrays =
     2
     3Thoughts on arrays and related issues.
     4
     5* drop C's silly pointer-array pun.  Pointers and arrays have nothing to do with each other.  In C,
     6{{{
     7void f(double[] x) {…}
     8double a[10];
     9
     10  f(a);
     11
     12}}}
     13is automatically converted to
     14{{{
     15void f(double *x) {…}
     16double a[10];
     17
     18  f(&a[0]);
     19
     20}}}
     21In CIVL-C (CIVL?), you write the one you mean.
     22
     23* Arrays are values just like any other kind of value (similar to structs).  They can be passed as arguments to functions and returned by functions.
     24
     25* The incomplete array type "array of t", denoted `t[]`, can be used (almost) anywhere a type is expected, including the element type of an array type.   The domain of `t[]` is all arrays of `t`, of any length.  A complete type `t[n]` is a subtype of `t[]`.  Example:
     26{{{
     27  $message[] append_message($message[] queue, $message m);
     28}}}
     29takes an array of messages and returns an array one longer which is equivalent to the original array with $m$ added.  There is no "sharing" between these two arrays.
     30
     31* Instead of malloc, introduce an operator `$alloc(heap, type)` where `heap` is an expression of type pointer-to-heap and `type` is a type name.  The type of this expression is pointer-to-`type`.  It allocates an object of the given type on the specified heap and returns a pointer to that object.