- Timestamp:
- Dec 23, 2025, 8:56:16 AM (3 days ago)
- Branches:
- master
- Parents:
- 80e83b6c
- File:
-
- 1 edited
-
doc/theses/mike_brooks_MMath/array.tex (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/array.tex
r80e83b6c r4904b05 1782 1782 m@[0][1]@ = 3; // subscript 1783 1783 \end{cfa} 1784 The alternative \CFA syntax is a comma separated list .1784 The alternative \CFA syntax is a comma separated list: 1785 1785 \begin{cfa} 1786 1786 int m@[2, 3]@; // dimension … … 1788 1788 \end{cfa} 1789 1789 which should be intuitive to C programmers and is used in mathematics $M_{i,j}$ and other programing languages, \eg PL/I, Fortran. 1790 With respect to the dimension expressions, C only allows an assignment expression .1790 With respect to the dimension expressions, C only allows an assignment expression, not a comma expression. 1791 1791 \begin{cfa} 1792 1792 a[i, j]; 1793 1793 test.c:3:16: error: expected ']' before ',' token 1794 1794 \end{cfa} 1795 However, there is an ambiguity for a single dimension array, where the syntax for old and new arrays are the same .1795 However, there is an ambiguity for a single dimension array, where the syntax for old and new arrays are the same, @int ar[10]@. 1796 1796 The solution is to use a terminating comma to denote a \CFA-style single-dimension array. 1797 1797 \begin{cfa} 1798 int m[2$\Huge\color{red},$]; // single dimension1798 int ar[2$\Huge\color{red},$]; // single dimension new array 1799 1799 \end{cfa} 1800 1800 This syntactic form is also used for the (rare) singleton tuple @[y@{\Large\color{red},}@]@. … … 1804 1804 With respect to the subscript expression, the comma expression is allowed. 1805 1805 However, a comma expression in this context is rare, and is most commonly a (silent) mistake: subscripting a matrix with @m[i, j]@ instead of @m[i][j]@ selects the @j@th row not the @i, j@ element. 1806 Finally, it is possible to write @m[(i, j)]@ in the new syntax to achieve the equivalent of the old @m[i, j]@. 1806 It is still possible to write @m[(i, j)]@ in the new syntax to achieve the equivalent of the old @m[i, j]@. 1807 Internally, the compiler must de-sugar @[i, j, k]@ into @[i][j][k]@ to match with three calls to subscript operators. 1807 1808 Note, there is no ambiguity for subscripting a single dimensional array, as the subscript operator selects the correct form from the array type. 1808 Currently, @array@ supports the old a md new subscript syntax \see{\VRef{f:ovhd-treat-src}}, including combinations of new and old, @arr[1, 2][3]@.1809 Finally, the new syntax is trivially lowered to C-style dimension and subscripting.1809 Currently, @array@ supports the old and new subscript syntax \see{\VRef[Figure]{f:ovhd-treat-src}}, including combinations of new and old, @arr[1, 2][3]@. 1810 The new subscript syntax can be extended to C arrays for uniformity, but requires the non-compatible removal of the (rare) comma-expression as a subscript. 1810 1811 1811 1812
Note:
See TracChangeset
for help on using the changeset viewer.