Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r59e86eb re9a3c69d  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon Jul 17 13:06:40 2017
    14 %% Update Count     : 2825
     13%% Last Modified On : Thu Jul 13 11:44:57 2017
     14%% Update Count     : 2690
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    353353The 1999 C standard plus GNU extensions.
    354354\item
    355 \Indexc[deletekeywords=inline]{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{\lstinline[deletekeywords=inline]$-fgnu89-inline$}}
     355{\lstset{deletekeywords={inline}}
     356\Indexc{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{©-fgnu89-inline©}}
    356357Use the traditional GNU semantics for inline routines in C99 mode, which allows inline routines in header files.
     358}%
    357359\end{description}
    358360The following new \CFA options are available:
     
    477479\end{cfa}
    478480Existing C programs with keyword clashes can be converted by enclosing keyword identifiers in backquotes, and eventually the identifier name can be changed to a non-keyword name.
    479 \VRef[Figure]{f:HeaderFileInterposition} shows how clashes in C header files (see~\VRef{s:StandardHeaders}) can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©:
     481\VRef[Figure]{f:InterpositionHeaderFile} shows how clashes in C header files (see~\VRef{s:StandardHeaders}) can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©:
    480482
    481483\begin{figure}
     
    485487#define otype ®`®otype®`®               §\C{// make keyword an identifier}§
    486488#define __CFA_BFD_H__
    487 #endif
    488 
    489 ®#include_next <bfd.h>                  §\C{// must have internal check for multiple expansion}§
    490 ®
     489#endif // ! otype
     490
     491#®include_next® <bfd.h>                 §\C{// must have internal check for multiple expansion}§
     492
    491493#if defined( otype ) && defined( __CFA_BFD_H__ )        §\C{// reset only if set}§
    492494#undef otype
    493495#undef __CFA_BFD_H__
    494 #endif
    495 \end{cfa}
    496 \caption{Header-File Interposition}
    497 \label{f:HeaderFileInterposition}
     496#endif // otype && __CFA_BFD_H__
     497\end{cfa}
     498\caption{Interposition of Header File}
     499\label{f:InterpositionHeaderFile}
    498500\end{figure}
    499 
    500 
    501 \section{Exponentiation Operator}
    502 
    503 C, \CC, and Java (and many other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow}, to perform the exponentiation operation.
    504 \CFA extends the basic operators with the exponentiation operator ©?\?©\index{?\\?@\lstinline$?\?$} and ©?\=?©\index{?\\=?@\lstinline$?\=?$}, as in, ©x \ y© and ©x \= y©, which means $x^y$ and $x \leftarrow x^y$.
    505 The priority of the exponentiation operator is between the cast and multiplicative operators, so that ©w * (int)x \ (int)y * z© is parenthesized as ©((w * (((int)x) \ ((int)y))) * z)©.
    506 
    507 As for \Index{division}, there are exponentiation operators for integral and floating-point types, including the builtin \Index{complex} types.
    508 Unsigned integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication (or shifting if the base is 2).
    509 Signed integral exponentiation\index{exponentiation!signed integral} is performed with repeated multiplication (or shifting if the base is 2), but yields a floating-point result because $b^{-e}=1/b^e$.
    510 Hence, it is important to designate exponent integral-constants as unsigned or signed: ©3 \ 3u© return an integral result, while ©3 \ 3© returns a floating-point result.
    511 Floating-point exponentiation\index{exponentiation!floating point} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative.
    512 \begin{cfa}
    513 sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) | endl;
    514 256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i
    515 \end{cfa}
    516 Parenthesis are necessary for the complex constants or the expresion is parsed as ©1.0f+(2.0fi \ 3.0f)+2.0fi©.
    517 The exponentiation operator is available for all the basic types, but for user-defined types, only the integral version is available, if the user type defines multiplication, ©*©, and one, ©1©.
    518501
    519502
     
    939922        int i, j;
    940923        int mem() {              ®// implicit "this" parameter
    941 ®               i = 1;          ®// this->i
     924                i = 1;          ®// this->i
    942925®               j = 3;          ®// this->j
    943926®       }
     
    946929Since CFA is non-object-oriented, the equivalent object-oriented program looks like:
    947930\begin{cfa}
    948 struct S { int i, j; };
    949 int mem( S &this ) {    // explicit "this" parameter
     931struct C {
     932        int i, j;
     933};
     934int mem( C &this ) {    // explicit "this" parameter
    950935        ®this.®i = 1;                     // "this" is not elided
    951936        ®this.®j = 2;
     
    953938\end{cfa}
    954939but it is cumbersome having to write "©this.©" many times in a member.
    955 
    956 \CFA provides a ©with© clause/statement to elided the "©this.©" by opening a scope containing field identifiers and changing the qualified fields into variables, giving an opportunity for optimizing qualified references.\footnote{
    957 The ©with© statement comes from Pascal~\cite[\S~4.F]{Pascal}.}
    958 \begin{cfa}
    959 int mem( S &this ) ®with this® {
     940\CFA provides a ©with© clause/statement to elided the "©this.©".
     941\begin{cfa}
     942int mem( C &this ) ®with this® {
    960943        i = 1;                  ®// this.i
    961944®       j = 2;                  ®// this.j
     
    964947which extends to multiple routine parameters:
    965948\begin{cfa}
    966 struct T { double m, n; };
    967 int mem2( S &this1, T &this2 ) ®with this1, this2® {
     949struct D {
     950        double m, n;
     951};
     952int mem2( C &this1, D &this2 ) ®with this1, this2® {
    968953        i = 1; j = 2;
    969954        m = 1.0; n = 2.0;
    970955}
    971956\end{cfa}
     957The ©with© clause/statement comes from Pascal~\cite[\S~4.F]{Pascal}.
    972958
    973959The statement form is used within a block:
     
    979965                // access fields of s1 without qualification
    980966                ®with s2® {  // nesting
    981                         // access fields of s1 and s2 without qualification
     967                        // access fields of s2 without qualification
    982968                }
    983969        }
     
    988974\end{cfa}
    989975
    990 When opening multiple structures, fields with the same name and type are ambiguous and must be fully qualified.
    991 For fields with the same name but different type, context/cast can be used to disambiguate.
    992 \begin{cfa}
    993 struct S { int i; int j; double m; } a, c;
    994 struct T { int i; int k; int m } b, c;
     976Names clashes when opening multiple structures are ambiguous.
     977\begin{cfa}
     978struct A { int i; int j; } a, c;
     979struct B { int i; int k; } b, c;
    995980®with a, b® {
    996         j + k;                                          §\C{// unambiguous, unique names define unique type}§
    997         i;                                                      §\C{// ambiguous, same name and type}§
    998         a.i + b.i;                                      §\C{// unambiguous, qualification defines unique type}§
    999         m;                                                      §\C{// ambiguous, no context to define unique type}§
    1000         m = 5.0;                                        §\C{// unambiguous, context defines unique type}§
    1001         m = 1;                                          §\C{// unambiguous, context defines unique type}§
    1002 }
    1003 ®with c® { ... }                                §\C{// ambiguous, no context}§
    1004 ®with (S)c® { ... }                             §\C{// unambiguous, cast defines unique type}§
     981        j + k;                                          §\C{// unambiguous}§
     982        i;                                                      §\C{// ambiguous}§
     983        a.i + b.i;                                      §\C{// unambiguous}§
     984}
     985®with c® {                                              §\C{// ambiguous}§
     986        // ...
     987}
    1005988\end{cfa}
    1006989
    1007990
    1008991\section{Exception Handling}
    1009 \label{s:ExceptionHandling}
    1010992
    1011993Exception handling provides two mechanism: change of control flow from a raise to a handler, and communication from the raise to the handler.
    1012 Transfer of control can be local, within a routine, or non-local, among routines.
    1013 Non-local transfer can cause stack unwinding, i.e., non-local routine termination, depending on the kind of raise.
    1014 \begin{cfa}
    1015 exception_t E {};                               §\C{// exception type}§
     994\begin{cfa}
     995exception void h( int i );
     996exception int h( int i, double d );
     997
    1016998void f(...) {
    1017         ... throw E{}; ...                      §\C{// termination}§
    1018         ... throwResume E{}; ...        §\C{// resumption}§
    1019 }
     999        ... throw h( 3 );
     1000        ... i = resume h( 3, 5.1 );
     1001}
     1002
    10201003try {
    10211004        f(...);
    1022 } catch( E e : §boolean-predicate§ ) {                  §\C{// termination handler}§
    1023         // recover and continue
    1024 } catchResume( E e : §boolean-predicate§ ) {    §\C{// resumption handler}§
    1025         // repair and return
     1005} catch h( int w ) {
     1006        // reset
     1007} resume h( int p, double x ) {
     1008        return 17;  // recover
    10261009} finally {
    1027         // always executed
    1028 }
    1029 \end{cfa}
    1030 The kind of raise and handler match: ©throw© with ©catch© and @throwResume@ with @catchResume@.
    1031 Then the exception type must match along with any additonal predicate must be true.
    1032 The ©catch© and ©catchResume© handlers may appear in any oder.
    1033 However, the ©finally© clause must
     1010}
     1011\end{cfa}
     1012So the type raised would be the mangled name of the exception prototype and that name would be matched at the handler clauses by comparing the strings.
     1013The arguments for the call would have to be packed in a message and unpacked at handler clause and then a call made to the handler.
    10341014
    10351015
     
    15911571
    15921572\item
    1593 lvalue to reference conversion: \lstinline[deletekeywords=lvalue]$lvalue-type cv1 T$ converts to ©cv2 T &©, which allows implicitly converting variables to references.
     1573lvalue to reference conversion: \lstinline[deletekeywords={lvalue}]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references.
    15941574\begin{cfa}
    15951575int x, &r = ®x®, f( int & p ); // lvalue variable (int) convert to reference (int &)
     
    27002680\begin{cfa}[belowskip=0pt]
    27012681char store[®sepSize®];                                          §\C{// sepSize is the maximum separator size}§
    2702 strcpy( store, sepGet( sout ) );                          §\C{// copy current separator}§
    2703 sepSet( sout, "_" );                                            §\C{// change separator to underscore}§
     2682strcpy( store, sepGet( sout ) );
     2683sepSet( sout, "_" );
    27042684sout | 1 | 2 | 3 | endl;
    27052685\end{cfa}
     
    27082688\end{cfa}
    27092689\begin{cfa}[belowskip=0pt]
    2710 sepSet( sout, store );                                          §\C{// change separator back to original}§
     2690sepSet( sout, store );
    27112691sout | 1 | 2 | 3 | endl;
    27122692\end{cfa}
     
    55835563\Celeven prescribes the following standard header-files~\cite[\S~7.1.2]{C11} and \CFA adds to this list:
    55845564\begin{quote2}
    5585 \begin{tabular}{@{}lllll|l@{}}
    5586 \multicolumn{5}{c|}{C11} & \multicolumn{1}{c}{\CFA}             \\
     5565\lstset{deletekeywords={float}}
     5566\begin{tabular}{@{}llll|l@{}}
     5567\multicolumn{4}{c|}{C11} & \multicolumn{1}{c}{\CFA}             \\
    55875568\hline
    55885569\begin{tabular}{@{}l@{}}
     
    55925573\Indexc{errno.h}                \\
    55935574\Indexc{fenv.h}                 \\
    5594 \Indexc[deletekeywords=float]{float.h} \\
     5575\Indexc{float.h}                \\
     5576\Indexc{inttypes.h}             \\
     5577\Indexc{iso646.h}               \\
    55955578\end{tabular}
    55965579&
    55975580\begin{tabular}{@{}l@{}}
    5598 \Indexc{inttypes.h}             \\
    5599 \Indexc{iso646.h}               \\
    56005581\Indexc{limits.h}               \\
    56015582\Indexc{locale.h}               \\
    56025583\Indexc{math.h}                 \\
    56035584\Indexc{setjmp.h}               \\
    5604 \end{tabular}
    5605 &
    5606 \begin{tabular}{@{}l@{}}
    56075585\Indexc{signal.h}               \\
    56085586\Indexc{stdalign.h}             \\
    56095587\Indexc{stdarg.h}               \\
    56105588\Indexc{stdatomic.h}    \\
    5611 \Indexc{stdbool.h}              \\
    5612 \Indexc{stddef.h}               \\
    56135589\end{tabular}
    56145590&
    56155591\begin{tabular}{@{}l@{}}
     5592\Indexc{stdbool.h}              \\
     5593\Indexc{stddef.h}               \\
    56165594\Indexc{stdint.h}               \\
    56175595\Indexc{stdio.h}                \\
     
    56295607\Indexc{wctype.h}               \\
    56305608                                                \\
     5609                                                \\
     5610                                                \\
    56315611\end{tabular}
    56325612&
     
    56345614\Indexc{unistd.h}               \\
    56355615\Indexc{gmp.h}                  \\
     5616                                                \\
     5617                                                \\
    56365618                                                \\
    56375619                                                \\
     
    56735655The table shows allocation routines supporting different combinations of storage-management capabilities:
    56745656\begin{center}
    5675 \begin{tabular}{@{}r|r|l|l|l|l@{}}
    5676 \multicolumn{1}{c}{}&           & \multicolumn{1}{c|}{fill}     & resize        & alignment     & array \\
     5657\begin{tabular}{@{}lr|l|l|l|l@{}}
     5658                &                                       & \multicolumn{1}{c|}{fill}     & resize        & alignment     & array \\
    56775659\hline
    56785660C               & ©malloc©                      & no                    & no            & no            & no    \\
     
    56815663                & ©memalign©            & no                    & no            & yes           & no    \\
    56825664                & ©posix_memalign©      & no                    & no            & yes           & no    \\
    5683 \hline
    56845665C11             & ©aligned_alloc©       & no                    & no            & yes           & no    \\
    5685 \hline
    56865666\CFA    & ©alloc©                       & no/copy/yes   & no/yes        & no            & yes   \\
    56875667                & ©align_alloc©         & no/yes                & no            & yes           & yes   \\
Note: See TracChangeset for help on using the changeset viewer.