source:doc/theses/lynn_tran_SE499/Chapters/CFA.tex@1e24d13

Last change on this file since 1e24d13 was 1b34b87, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

Lynn's GDB essay

• Property mode set to 100644
File size: 4.6 KB
Line
1\chapter{\CFA} \label{CFA}
2
3\section{Introduction}
4Similar to \CC, C is a popular programming language especially in systems
5programming. For example, the Windows NT and Linux kernel are written in C, and they are the foundation of many higher level
6and popular projects. Therefore, it is unlikely that the programming language C is
7going to disappear any time soon.
8
9However, C has inherent problems in syntax, semantics and many
10more \cite{Reference2}. Even though \CC is meant to fix these problems, \CC has many
11irreversible legacy design choices, and newer versions of \CC require significantly more effort to convert C-based projects into \CC.
12
13To solve this problem, the programming language \CFA is being created at the University of Waterloo. The goal
14of the language is to extend C with modern language features that many new
15languages have, such as Rust and Go. Hence, the \CFA extension provides a
16backward-compatible version of C, while fixing existing problems known in C and
17modernizing the language at the same time.
18
20Overloading is when a compiler permits a name to have multiple meanings. All
22as the \verb|+| operator (add) on integer and floating-point types. Most programming languages extend
25
26\subsection{Variable}
27Variables in the same block are allowed to have the same name but different
28types. An assignment to a new variable uses that variable's type to infer the
29required type, and that type is used to select a variable containing the appropriate type.
30
32short int MAX = SHRT_MAX;
33int MAX = INT_MAX;
34double MAX = DBL_MAX;
35
36// select variable MAX based on its left-hand type
37short int s = MAX;      // s = SHRT_MAX
38int s = MAX;            // s = INT_MAX
39double s = MAX;         // s = DBL_MAX
40\end{lstlisting}
41
43in the same scope, the variable is selected based on the left side of
44initialization/assignment and operands of the right side of the expression. For
45instance, the first assignment to variable \verb|s| at line 6, which is type short int,
46selects the MAX with the same type.
47
48\subsection{Function}
49Functions in the same block can be overloaded depending on the number and type of
50parameters and returns.
51
54void f(<@\textcolor{red}{void}@>);              // (1)
55void f(<@\textcolor{red}{char}@>);              // (2)
56<@\textcolor{red}{char}@> f(void);              // (3)
57<@\textcolor{red}{[int,double]}@> f();           // (4)
58
59f();                      // pick (1)
60f('a');                   // pick (2)
61char s = f('a');          // pick (3)
62[int, double] s = f();    // pick (4)
63\end{lstlisting}
64
66the same scope, a function is selected based on the combination of its return type and its
67arguments. For instance, from line 1-4, four different types of a function called
68\verb|f| are declared. For the call \verb|f('a')|, the function selected is the
69one on line 2, if the call voids the result. However, if the call assigns to a
70char, then the routine on line 3 is selected. This example can be seen on lines
717-8.
72
73\subsection{Operator}
74An operator name is denoted with \verb|?| for the operand and any standard C
75operator. Operator names within the same block can be overloaded depending on
76the number and type of parameters and returns. However, operators \verb|&&|,
77\verb-||-, \verb|?:| cannot be overloaded because short-circuit semantics
78cannot be preserved.
79
80
83int <@\textcolor{red}{++?}@>(int op);           // unary prefix increment
84int <@\textcolor{red}{?++}@>(int op);           // unary postfix increment
85int <@\textcolor{red}{?+?}@>(int op1, int op2); // unary postfix increment
86
87struct S { double x, double y }
88