\chapter{Introduction}

All modern programming languages provide three high-level containers (collection): array, linked, and string.
Often array is part of the programming language, while linked is built from pointer types, and string from a combination of array and linked.

\cite{Blache19}
\cite{Oorschot23}
\cite{Ruef19}

\section{Array}

Array provides a homogeneous container with $O(1)$ access to elements using subscripting.
The array size can be static, dynamic but fixed after creation, or dynamic and variable after creation.
For static and dynamic-fixed, an array can be stack allocated, while dynamic-variable requires the heap.


\section{Linked List}

Linked provides a homogeneous container with $O(log N)$/$O(N)$ access to elements using successor and predecessor operations.
Subscripting by value is sometimes available.
Linked types are normally dynamically sized by adding/removing node using link fields internal or external to the elements (nodes).
If a programming language allows pointer to stack storage, linked types can be allocated on the stack;
otherwise, elements are heap allocated and explicitly/implicitly managed.


\section{String}

String provides a dynamic array of homogeneous elements, where the elements are often human-readable characters.
What 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.
Nevertheless, subscripting is often available.
The cost of string operations is less important than the power of the block operation to accomplish complex manipulation.
The dynamic nature of string means storage is normally heap allocated but often implicitly managed, even in unmanaged languages.


\section{Motivation}

The goal of this work is to introduce safe and complex versions of array, link, and string into the programming language \CFA, which based on C.
Unfortunately, to make C better while retaining a high level of backwards compatibility requires a significant knowledge of C's design.
Hence, it is assumed the reader has a medium knowledge of C or \CC, on which extensive new C knowledge is built.


\subsection{C?}

Like many established programming languages, C has a standards committee and multiple ANSI/ISO language manuals~\cite{C99,C11,C18,C23}.
However, most programming languages are only partially explained by these manuals.
When it comes to explaining how C works, the definitive source is the @gcc@ compiler, which is mimicked by other C compilers, such as Clang~\cite{clang}.
Often other C compilers must \emph{ape} @gcc@ because a large part of the C library (runtime) system is embedded with @gcc@ features.
While some key aspects of C need to be explained by quoting from the language reference manual, to illustrate definite program semantics, I devise a program, whose behaviour exercises the point at issue, and shows its behaviour.
These example programs show
\begin{itemize}
	\item the compiler accepts or rejects certain syntax,
	\item the prints output to buttress a claim of behaviour,
	\item executes without triggering any embedded assertions testing pre/post-assertions or invariants.
\end{itemize}
This work has been tested across @gcc@ versions 8--12 and clang version 10 running on ARM, AMD, and Intel architectures.
Any discovered anomalies among compilers or versions is discussed.
In this case, I do not argue that my sample of major Linux compilers is doing the right thing with respect to the C standard.


\subsection{Ill-Typed Expressions}

C reports many ill-typed expressions as warnings.
For example, these attempts to assign @y@ to @x@ and vice-versa are obviously ill-typed.
\lstinput{12-15}{bkgd-c-tyerr.c}
with warnings:
\begin{cfa}
warning: assignment to 'float *' from incompatible pointer type 'void (*)(void)'
warning: assignment to 'void (*)(void)' from incompatible pointer type 'float *'
\end{cfa}
Similarly,
\lstinput{17-19}{bkgd-c-tyerr.c}
with warning:
\begin{cfa}
warning: passing argument 1 of 'f' from incompatible pointer type
note: expected 'void (*)(void)' but argument is of type 'float *'
\end{cfa}
with a segmentation fault at runtime.
Clearly, @gcc@ understands these ill-typed case, and yet allows the program to compile, which seems like madness.
Compiling with @-Werror@, which turns warnings into errors, is often too strong, because some warnings are just warnings.
In the following discussion, ``ill-typed'' means giving a nonzero @gcc@ exit condition with a message that discusses typing.
Note, \CFA's type-system rejects all these ill-typed cases as type mismatch errors.

% That @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@.
% Rather, 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.

% A "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.
% The behaviour (whose absence is unprovable) is neither minor nor unlikely.
% The rejection shows that the program is ill-typed.
% 
% Yet, the rejection presents as a GCC warning.
% *1  TAPL-pg1 definition of a type system


\section{Contributions}

\subsection{Linked List}

\subsection{Array}

\subsection{String}
