Changeset 7d95bce9
- Timestamp:
- Nov 4, 2024, 12:21:11 PM (3 weeks ago)
- Branches:
- master
- Children:
- 97ac01d3
- Parents:
- c3e41cda
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/background.tex
rc3e41cda r7d95bce9 685 685 Here, the distance between the first and second elements of each array depends on the inner dimension size. 686 686 687 The last observation is a fact of the callee's perspective. 688 There is little type-system checking, in the caller's perspective, that what is being passed, matches. 689 \PAB{I do not understand} 690 \begin{cfa} 691 void f( float [][10] ); 692 int n = 100; 693 float a[100], b[n]; 694 f(&a); // reject 695 f(&b); // accept 696 687 This significance of an inner dimension's length is a fact of the callee's perspective. 688 In the caller's perspective, the type sytem is quite lax. 689 Here, there is (some, but) little checking that what is being passed, matches. 690 % void f( float [][10] ); 691 % int n = 100; 692 % float a[100], b[n]; 693 % f(&a); // reject 694 % f(&b); // accept 695 \begin{cfa} 697 696 void foo() { 698 697 void f( float [][10] ); 699 698 int n = 100; 700 699 float a[100], b[3][12], c[n], d[n][n]; 701 f( a ); // reject702 f( b ); // reject703 f( c ); // reject704 f( d ); // accept705 f( &a ); // reject706 f( &b ); // reject707 f( &c ); // accept708 f( &d ); // reject700 f( a ); 701 f( b ); $\C{// reject: inner dimension 12 for 10}$ 702 f( c ); 703 f( @d@ ); $\C{// accept with inner dimension n for 10}$ 704 f( &a ); $\C{// reject: inner dimension 100 for 10}$ 705 f( &b ); 706 f( @&c@ ); $\C{// accept with inner dimension n for 10}$ 707 f( &d ); 709 708 } 710 709 \end{cfa} 711 This size is therefore, a callee's assumption. 710 The cases without comments are rejections, but simply because the array ranks do not match; in the commented cases, the ranks match and the rules being discussed apply. 711 The cases @f(b)@ and @f(&a)@ show where some length checking occurs. 712 But this checking misses the cases @f(d)@ and @f(&c)@, allowing the calls with mismatched lengths, actually 100 for 10. 713 The C checking rule avoids false alarms, at the expense of safety, by allowing any combinations that involve dynamic values. 714 Ultimately, an inner dimension's size is a callee's \emph{assumption} because the type system uses declaration details in the callee's perspective that it does not enforce in the caller's perspective. 712 715 713 716 Finally, to handle higher-dimensional VLAs, C repurposed the @*@ \emph{within} the dimension in a declaration to mean that the callee has make an assumption about the size, but no (unchecked, possibly wrong) information about this assumption is included for the caller-programmer's benefit/over-confidence.
Note: See TracChangeset
for help on using the changeset viewer.