Changeset 6a8c773
- Timestamp:
- Mar 24, 2024, 11:08:46 PM (9 months ago)
- Branches:
- master
- Children:
- 41fb996
- Parents:
- 82e5670
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/intro.tex
r82e5670 r6a8c773 33 33 34 34 35 \section{ C/\CFA}35 \section{Motivation} 36 36 37 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 the C. 37 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. 38 Unfortunately, to make C better while retaining a high level of backwards compatibility requires a significant knowledge of C's design. 39 Hence, it is assumed the reader has a medium knowledge of C or \CC, on which extensive new C knowledge is built. 38 40 39 41 40 \subsection{C ommon knowledge}42 \subsection{C?} 41 43 42 The reader is assumed to have used C or \CC for the coursework of at least four university-level courses, or have equivalent experience. 43 The 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 49 When it comes to explaining how C works, I like illustrating definite program semantics. 50 I prefer doing so, over a quoting manual's suggested programmer's intuition, or showing how some compiler writers chose to model their problem. 51 To illustrate definite program semantics, I devise a program, whose behaviour exercises the point at issue, and I show its behaviour. 52 53 This behaviour is typically one of 44 Like many established programming languages, C has a standards committee and multiple ANSI/ISO language manuals~\cite{C99,C11,C18,C23}. 45 However, most programming languages are only partially explained by these manuals. 46 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}. 47 Often other C compilers must \emph{ape} @gcc@ because a large part of the C library (runtime) system is embedded with @gcc@ features. 48 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. 49 These example programs show 54 50 \begin{itemize} 55 \item my statement that the compiler accepts or rejects the program56 \item the pr ogram's printed output, which I show57 \item my implied assurance that its assertions do not fail when run51 \item the compiler accepts or rejects certain syntax, 52 \item the prints output to buttress a claim of behaviour, 53 \item executes without triggering any embedded assertions testing pre/post-assertions or invariants. 58 54 \end{itemize} 59 60 The compiler whose program semantics is shown is 61 \begin{cfa} 62 $ gcc --version 63 gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 64 \end{cfa} 65 running on Architecture @x86_64@, with the same environment targeted. 66 67 Unless 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. 55 This work has been tested across @gcc@ versions 8--12 and clang version 10 running on ARM, AMD, and Intel architectures. 56 Any discovered anomalies among compilers or versions is discussed. 68 57 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. 69 58 70 59 71 \subsection{ C reports many ill-typed expressions as warnings}60 \subsection{Ill-Typed Expressions} 72 61 73 These attempts to assign @y@ to @x@ and vice-versa are obviously ill-typed. 62 C reports many ill-typed expressions as warnings. 63 For example, these attempts to assign @y@ to @x@ and vice-versa are obviously ill-typed. 74 64 \lstinput{12-15}{bkgd-c-tyerr.c} 75 65 with warnings: … … 86 76 \end{cfa} 87 77 with a segmentation fault at runtime. 78 Clearly, @gcc@ understands these ill-typed case, and yet allows the program to compile, which seems like madness. 79 Compiling with @-Werror@, which turns warnings into errors, is often too strong, because some warnings are just warnings. 80 In the following discussion, ``ill-typed'' means giving a nonzero @gcc@ exit condition with a message that discusses typing. 81 Note, \CFA's type-system rejects all these ill-typed cases as type mismatch errors. 88 82 89 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@.90 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.83 % 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@. 84 % 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. 91 85 92 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. 93 The behaviour (whose absence is unprovable) is neither minor nor unlikely. 94 The rejection shows that the program is ill-typed. 95 96 Yet, the rejection presents as a GCC warning. 97 98 In 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 86 % 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. 87 % The behaviour (whose absence is unprovable) is neither minor nor unlikely. 88 % The rejection shows that the program is ill-typed. 89 % 90 % Yet, the rejection presents as a GCC warning. 91 % *1 TAPL-pg1 definition of a type system 101 92 102 93
Note: See TracChangeset
for help on using the changeset viewer.