source: doc/theses/mike_brooks_MMath/intro.tex @ bdc8591

Last change on this file since bdc8591 was bdc8591, checked in by Peter A. Buhr <pabuhr@…>, 3 months ago

start introduction

  • Property mode set to 100644
File size: 5.1 KB
Line 
1\chapter{Introduction}
2
3All modern programming languages provide three high-level containers (collection): array, linked, and string.
4Often array is part of the programming language, while linked is built from pointer types, and string from a combination of array and linked.
5
6\cite{Blache19}
7\cite{Oorschot23}
8\cite{Ruef19}
9
10\section{Array}
11
12Array provides a homogeneous container with $O(1)$ access to elements using subscripting.
13The array size can be static, dynamic but fixed after creation, or dynamic and variable after creation.
14For static and dynamic-fixed, an array can be stack allocated, while dynamic-variable requires the heap.
15
16
17\section{Linked List}
18
19Linked provides a homogeneous container with $O(log N)$/$O(N)$ access to elements using successor and predecessor operations.
20Subscripting by value is sometimes available.
21Linked types are normally dynamically sized by adding/removing node using link fields internal or external to the elements (nodes).
22If a programming language allows pointer to stack storage, linked types can be allocated on the stack;
23otherwise, elements are heap allocated and explicitly/implicitly managed.
24
25
26\section{String}
27
28String provides a dynamic array of homogeneous elements, where the elements are often human-readable characters.
29What differentiates string from other types in that string operations work on blocks of elements for scanning and changing the elements, rather than accessing individual elements.
30Nevertheless, subscripting is often available.
31The cost of string operations is less important than the power of the block operation to accomplish complex manipulation.
32The dynamic nature of string means storage is normally heap allocated but often implicitly managed, even in unmanaged languages.
33
34
35\section{C/\CFA}
36
37The goal of this work is to introduce safe and complex versions of array, link, and string into the programming language \CFA, which based on the C.
38
39
40\subsection{Common knowledge}
41
42The reader is assumed to have used C or \CC for the coursework of at least four university-level courses, or have equivalent experience.
43The current discussion introduces facts, unaware of which, such a functioning novice may be operating.
44
45% TODO: decide if I'm also claiming this collection of facts, and test-oriented presentation is a contribution; if so, deal with (not) arguing for its originality
46
47\subsection{Convention: C is more touchable than its standard}
48
49When it comes to explaining how C works, I like illustrating definite program semantics.
50I prefer doing so, over a quoting manual's suggested programmer's intuition, or showing how some compiler writers chose to model their problem.
51To illustrate definite program semantics, I devise a program, whose behaviour exercises the point at issue, and I show its behaviour.
52
53This behaviour is typically one of
54\begin{itemize}
55        \item my statement that the compiler accepts or rejects the program
56        \item the program's printed output, which I show
57        \item my implied assurance that its assertions do not fail when run
58\end{itemize}
59
60The compiler whose program semantics is shown is
61\begin{cfa}
62$ gcc --version
63gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
64\end{cfa}
65running on Architecture @x86_64@, with the same environment targeted.
66
67Unless explicit discussion ensues about differences among compilers or with (versions of) the standard, it is further implied that there exists a second version of GCC and some version of Clang, running on and for the same platform, that give substantially similar behaviour.
68In this case, I do not argue that my sample of major Linux compilers is doing the right thing with respect to the C standard.
69
70
71\subsection{C reports many ill-typed expressions as warnings}
72
73These attempts to assign @y@ to @x@ and vice-versa are obviously ill-typed.
74\lstinput{12-15}{bkgd-c-tyerr.c}
75with warnings:
76\begin{cfa}
77warning: assignment to 'float *' from incompatible pointer type 'void (*)(void)'
78warning: assignment to 'void (*)(void)' from incompatible pointer type 'float *'
79\end{cfa}
80Similarly,
81\lstinput{17-19}{bkgd-c-tyerr.c}
82with warning:
83\begin{cfa}
84warning: passing argument 1 of 'f' from incompatible pointer type
85note: expected 'void (*)(void)' but argument is of type 'float *'
86\end{cfa}
87with a segmentation fault at runtime.
88
89That @f@'s attempt to call @g@ fails is not due to 3.14 being a particularly unlucky choice of value to put in the variable @pi@.
90Rather, it is because obtaining a program that includes this essential fragment, yet exhibits a behaviour other than "doomed to crash," is a matter for an obfuscated coding competition.
91
92A "tractable syntactic method for proving the absence of certain program behaviours by classifying phrases according to the kinds of values they compute"*1 rejected the program.
93The behaviour (whose absence is unprovable) is neither minor nor unlikely.
94The rejection shows that the program is ill-typed.
95
96Yet, the rejection presents as a GCC warning.
97
98In the discussion following, ``ill-typed'' means giving a nonzero @gcc -Werror@ exit condition with a message that discusses typing.
99
100*1  TAPL-pg1 definition of a type system
101
102
103\section{Contributions}
104
105\subsection{Linked List}
106
107\subsection{Array}
108
109\subsection{String}
Note: See TracBrowser for help on using the repository browser.