Changes in doc/user/user.tex [9724df0:45576af9]
- File:
-
- 1 edited
-
doc/user/user.tex (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r9724df0 r45576af9 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Mon Jun 20 10:47:22 201614 %% Update Count : 57513 %% Last Modified On : Fri Jun 10 16:38:22 2016 14 %% Update Count : 394 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 21 21 % blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_ 22 22 % green highlighting ¢...¢ (cent symbol) emacs: C-q M-" 23 % La Tex escape §...§ (section symbol) emacs: C-q M-'23 % Latex escape §...§ (section symbol) emacs: C-q M-' 24 24 % keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^ 25 25 % math escape $...$ (dollar symbol) 26 26 27 27 \documentclass[twoside,11pt]{article} 28 29 28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 30 29 … … 35 34 \usepackage{fullpage,times,comment} 36 35 \usepackage{epic,eepic} 37 \usepackage{upquote} % switch curled `'" to straight 36 \usepackage{upquote} % switch curled `'" to straight `'" 38 37 \usepackage{xspace} 39 38 \usepackage{varioref} % extended references … … 50 49 \renewcommand{\UrlFont}{\small\sf} 51 50 52 \makeatletter53 \renewcommand{\pagestyle}[1]{54 \@ifundefined{ps@#1}%55 \undefinedpagestyle56 {\def\@tempa{#1}\def\@tempb{headings}\def\@tempc{myheadings}%57 \ifx\@tempa\@tempb\setlength{\topmargin}{-0.25in}\setlength{\headsep}{0.25in}%58 \else\ifx\@tempa\@tempc\setlength{\topmargin}{-0.25in}\setlength{\headsep}{0.25in}\fi\fi%59 \@nameuse{ps@#1}}}% pagestyle60 \makeatother61 62 63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%64 65 51 % Names used in the document. 66 52 … … 74 60 \newcommand{\G}[1]{{\Textbf[OliveGreen]{#1}}} 75 61 76 \newsavebox{\LstBox}77 78 62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 79 63 … … 83 67 84 68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 69 70 \begin{document} 71 \pagestyle{headings} 72 \linenumbers % comment out to turn off line numbering 85 73 86 74 \title{\Huge … … 89 77 Version 1.0 \\ 90 78 \vspace*{0.25in} 91 \huge``describe not prescribe'' 79 \huge``describe not prescribe'' \\ 92 80 \vspace*{1in} 93 81 }% title 94 95 82 \author{\huge 96 Peter A. Buhr and ... 83 Peter A. Buhr and ... \\ 97 84 }% author 98 99 85 \date{ 100 DRAFT \\ \today 86 DRAFT \\ 87 \today 101 88 }% date 102 89 103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%104 105 \begin{document}106 \pagestyle{headings}107 90 \pagenumbering{roman} 108 \ linenumbers % comment out to turn off line numbering91 \pagestyle{plain} 109 92 110 93 \maketitle … … 124 107 125 108 \clearpage 126 \markright{\CFA User Manual}127 109 \pagenumbering{arabic} 128 110 … … 489 471 \end{quote2} 490 472 491 Unsupported are K\&R C declarations where the base type defaults to ©int©, if no type is specified ,\footnote{492 At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each structure declaration and type name~\cite[\S~6.7.2(2)]{C11}} 473 Unsupported are K\&R C declarations where the base type defaults to ©int©, if no type is specified\footnote{ 474 At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each structure declaration and type name~\cite[\S~6.7.2(2)]{C11}}, 493 475 e.g.: 494 476 \begin{lstlisting} … … 503 485 Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX systems. 504 486 505 506 \section{Reference Pointers}507 508 Program variables are implicit pointers to memory locations generated by the compiler and automatically dereferenced, as in:509 \begin{quote2}510 \begin{tabular}{@{}l|l@{}}511 \multicolumn{1}{c|}{Variables} & \multicolumn{1}{c}{Compiler generated addresses (100, 104) and dereferencing} \\512 \hline513 \begin{lstlisting}514 int x, y;515 x = 3;516 y = x;517 \end{lstlisting}518 &519 \begin{lstlisting}520 int * const x = (int *)100, * const y = (int *)104;521 *x = 3; // implicit dereference522 *y = *x;523 \end{lstlisting}524 \end{tabular}525 \end{quote2}526 A variable name only points to one location during its lifetime, i.e., it is a \Index{non-mutable} pointer.527 For example, the variables ©x© and ©y© are constant pointers.528 Variable addresses are usually not stored in memory and loaded before dereferencing;529 instead, variable addresses are stored in instructions, so an instruction fetch implicitly gets the variable's address.530 \begin{quote2}531 \begin{tabular}{@{}l|l@{}}532 \begin{lstlisting}533 x = x + 1534 &x = *(&x) + 1535 (100) = *(100) + 1536 \end{lstlisting}537 &538 \begin{lstlisting}539 ld r1,(100) // address of x540 add r1,1541 st r1,(100) // address of x542 \end{lstlisting}543 \end{tabular}544 \end{quote2}545 Finally, the non-mutable nature of variables and the fact that there is no storage for a variable address means pointer assignment is impossible.546 Therefore, the expression ©x = y© only has one meaning, ©*x = *y©, i.e., copy the variable values, so explicitly writing the dereferences is unnecessary even though it occurs implicitly as part of instruction decoding.547 548 A variable name is generalized by a \newterm{pointer}, which is a mutable pointer variable that can point to more than one memory location during its life-time (like an integer variable versus a literal).549 Hence, a pointer occupies memory to store its current address, and the pointer's value is loaded by dereferencing, e.g.:550 \begin{lstlisting}551 int x, y, z, ®*® p1, ®*® p2;552 p1 = ®&®x; // p1 points to x553 p2 = p1; // p2 also points to x554 p1 = ®&®y; // p1 points to y555 p2 = p1 + 1; // p2 points to z, pointer arithmetic556 \end{lstlisting}557 In many cases, a pointer name is anonymous (dynamically computed), so it cannot be stored directly in an instruction like a variable name.558 559 Pointers have a duality: an address in memory or the value at that address.560 In many cases, the compiler can infer which of these operations are needed:561 \begin{lstlisting}562 p2 = p1 + x; // compiler infers *p2 = *p1 + x;563 \end{lstlisting}564 because adding the integer value of ©x© to the address of ©p1© and storing the resulting address into ©p2© is an unlikely operation.565 Algol68~\cite{Algol68} inferences pointer dereferencing to select the best meaning for each pointer usage.566 However, there are ambiguous cases, especially when pointer arithmetic is possible, as in C:567 \begin{lstlisting}568 p1 = p2; // p1 = p2 or *p1 = *p2569 p1 = p1 + 1; // p1 = p1 + 1 or *p1 = *p1 + 1570 \end{lstlisting}571 572 Most programming languages pick a default operation and supply an explicit operation to resolve the pointer-duality ambiguity.573 In C, the default operation for pointers is manipulate the pointer value and the pointed-to value is explicitly accessed by dereferencing ©*©.574 \begin{lstlisting}575 p1 = p2; // pointer value assignment576 *p1 = *p1 + 1; // pointed-to value assignment/operation577 \end{lstlisting}578 which works well for low-level memory management, such as ©malloc©/©free©, where manipulation of addresses in the primary operation, and data is only occasionally accessed.579 580 However, in the majority of pointer usages, the pointed-to value is required rather than the pointer address.581 \begin{lstlisting}582 *p2 = ((*p1 + *p2) * (*p2 - *p1)) / (*p1 - *p2);583 \end{lstlisting}584 And, it is tedious and error prone to explicitly write the dereferencing, especially when pointer arithmetic with integer values is allowed.585 It is better to have the compiler generate the dereferencing:586 \begin{lstlisting}587 p2 = ((p1 + p2) * (p2 - p1)) / (p1 - p2);588 \end{lstlisting}589 590 To provide this capability, it is necessary to switch the default operation to resolve the pointer-duality ambiguity, which requires a new kind of pointer called a \newterm{reference} pointer.591 \begin{lstlisting}592 int x, y, z, ®&® r1, ®&® r2; // & denotes reference pointer593 r1 ®:=® &x; // r1 points to x594 r2 ®:=® &r1; // r2 also points to x595 r1 ®:=® &y; // r1 points to y596 r2 ®:=® &r1 + 1; // r2 points to z597 r2 = ((r1 + r2) * (r2 - r1)) / (r1 - r2); // implicit dereferencing598 \end{lstlisting}599 Hence, a reference pointer behaves like a variable name for the current variable it is pointing-to, so dereferencing a reference pointer returns the address of its pointed-to value, i.e., the address in the reference pointer.600 Notice, the explicit operator ©:=© to denote pointer assignment to a reference pointer to support both aspects of pointer duality.601 Note, \CC deals with the pointer duality by making a reference pointer a constant (©const©), like a plain variable, so there is no reference assignment.602 603 Like pointers, it is possible to use ©const© qualifiers with a reference:604 \begin{lstlisting}605 const int cx = 5; // cannot change cx;606 const int & r3 = &cx; // cannot change what r3 is pointing to607 r3 ®:=® &cx; // can change r3608 r3 = 7; // error, cannot change cx609 int & const r4 = &x; // must be initialized, §\CC§ reference610 r4 ®:=® &x; // error, cannot change r4611 const int & const r5 = &cx; // must be initialized, §\CC§ reference612 r5 = 7; // error, cannot change cx613 r5 ®:=® &cx; // error, cannot change r5614 \end{lstlisting}615 Note, for type ©& const©, there is no pointer assignment, so ©r4 := &x© is disallowed, and the pointer value cannot be ©0©.616 Since there is only one meaning for ©r4 = x©, which is to change the value of the variable pointed to by ©r4©, therefore:617 \begin{itemize}618 \item619 it in impossible to take the address of ©r4© as it always means the address of what ©r4© is pointing to.620 \item621 the dereference at initialization is optional because there can only be one622 \begin{lrbox}{\LstBox}%623 \footnotesize%624 \begin{lstlisting}%625 void f( int p ) {...}626 void (*fp)( int ) = &f; // equivalent initialization627 void (*fp)( int ) = f; // missing dereference allowed628 \end{lstlisting}%629 \end{lrbox}%630 meaning.\footnote{631 This case is similar to initializing a routine pointer, where the routine constant should be dereferenced.632 \newline633 \usebox{\LstBox}634 }% footnote635 \begin{lstlisting}636 int & const r4 = &x; // equivalent initialization637 int & const r4 = x; // missing dereference allowed638 \end{lstlisting}639 \end{itemize}640 Similarly, when a ©const© reference is used for a parameters type, the call-site argument does not require a reference.641 \begin{lstlisting}642 void f( int & ri, int & const cri );643 f( &x, x ); // reference not required for second argument644 \end{lstlisting}645 Within routine ©f©, it is possible to change an argument by changing the corresponding parameter, and parameter ©ri© can be locally reassigned within ©f©.646 647 Finally, when a reference parameter has a ©const© value, it is possible to pass literals and expressions.648 \begin{lstlisting}649 void g( const int & ri, const int & const cri );650 f( &3, 3 );651 f( &(x + y), x + y );652 \end{lstlisting}653 At the call site, the compiler implicitly creates the necessary temporary that is subsequently pointed to by the reference parameter.654 Hence, changing the parameter only changes the temporary at the call site.655 For the non-©const© parameter, requiring the reference on the literal or expression makes it clear that nothing is changing at the call site and allows the call to proceed, where other languages require the programmer to explicitly create the temporary for the argument.656 487 657 488 \section{Type Operators} … … 977 808 \subsection{Type Nesting} 978 809 979 \CFA allows \Index{type nesting}, and type qualification of the nested types (see \VRef[Figure]{f:TypeNestingQualification}), where as C hoists\index{type hoisting} (refactors) nested types into the enclosing scope and has no type qualification.980 \begin{ figure}810 \CFA allows \Index{type nesting}, and type qualification of the nested types, where as C hoists\index{type hoisting} (refactors) nested types into the enclosing scope and has no type qualification. 811 \begin{quote2} 981 812 \begin{tabular}{@{}l@{\hspace{3em}}l|l@{}} 982 813 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{C Type Nesting}} & \multicolumn{1}{c}{\textbf{C Implicit Hoisting}} & \multicolumn{1}{|c}{\textbf{\CFA}} \\ … … 1039 870 \end{lstlisting} 1040 871 \end{tabular} 1041 \caption{Type Nesting / Qualification} 1042 \label{f:TypeNestingQualification} 1043 \end{figure} 872 \end{quote2} 1044 873 In the left example in C, types ©C©, ©U© and ©T© are implicitly hoisted outside of type ©S© into the containing block scope. 1045 874 In the right example in \CFA, the types are not hoisted and accessed using the field-selection operator ``©.©'' for type qualification, as does Java, rather than the \CC type-selection operator ``©::©''.
Note:
See TracChangeset
for help on using the changeset viewer.