Changes in doc/user/user.tex [59e86eb:e9a3c69d]
- File:
-
- 1 edited
-
doc/user/user.tex (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r59e86eb re9a3c69d 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Mon Jul 17 13:06:40201714 %% Update Count : 2 82513 %% Last Modified On : Thu Jul 13 11:44:57 2017 14 %% Update Count : 2690 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 353 353 The 1999 C standard plus GNU extensions. 354 354 \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©}} 356 357 Use the traditional GNU semantics for inline routines in C99 mode, which allows inline routines in header files. 358 }% 357 359 \end{description} 358 360 The following new \CFA options are available: … … 477 479 \end{cfa} 478 480 Existing 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©: 480 482 481 483 \begin{figure} … … 485 487 #define otype ®`®otype®`® §\C{// make keyword an identifier}§ 486 488 #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 491 493 #if defined( otype ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§ 492 494 #undef otype 493 495 #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} 498 500 \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.1922i515 \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©.518 501 519 502 … … 939 922 int i, j; 940 923 int mem() { ®// implicit "this" parameter 941 ®i = 1; ®// this->i924 i = 1; ®// this->i 942 925 ® j = 3; ®// this->j 943 926 ® } … … 946 929 Since CFA is non-object-oriented, the equivalent object-oriented program looks like: 947 930 \begin{cfa} 948 struct S { int i, j; }; 949 int mem( S &this ) { // explicit "this" parameter 931 struct C { 932 int i, j; 933 }; 934 int mem( C &this ) { // explicit "this" parameter 950 935 ®this.®i = 1; // "this" is not elided 951 936 ®this.®j = 2; … … 953 938 \end{cfa} 954 939 but 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} 942 int mem( C &this ) ®with this® { 960 943 i = 1; ®// this.i 961 944 ® j = 2; ®// this.j … … 964 947 which extends to multiple routine parameters: 965 948 \begin{cfa} 966 struct T { double m, n; }; 967 int mem2( S &this1, T &this2 ) ®with this1, this2® { 949 struct D { 950 double m, n; 951 }; 952 int mem2( C &this1, D &this2 ) ®with this1, this2® { 968 953 i = 1; j = 2; 969 954 m = 1.0; n = 2.0; 970 955 } 971 956 \end{cfa} 957 The ©with© clause/statement comes from Pascal~\cite[\S~4.F]{Pascal}. 972 958 973 959 The statement form is used within a block: … … 979 965 // access fields of s1 without qualification 980 966 ®with s2® { // nesting 981 // access fields of s 1 and s2 without qualification967 // access fields of s2 without qualification 982 968 } 983 969 } … … 988 974 \end{cfa} 989 975 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; 976 Names clashes when opening multiple structures are ambiguous. 977 \begin{cfa} 978 struct A { int i; int j; } a, c; 979 struct B { int i; int k; } b, c; 995 980 ®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 } 1005 988 \end{cfa} 1006 989 1007 990 1008 991 \section{Exception Handling} 1009 \label{s:ExceptionHandling}1010 992 1011 993 Exception 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} 995 exception void h( int i ); 996 exception int h( int i, double d ); 997 1016 998 void 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 1020 1003 try { 1021 1004 f(...); 1022 } catch ( E e : §boolean-predicate§ ) { §\C{// termination handler}§1023 // re cover and continue1024 } catchResume( E e : §boolean-predicate§ ) { §\C{// resumption handler}§1025 // repair and return1005 } catch h( int w ) { 1006 // reset 1007 } resume h( int p, double x ) { 1008 return 17; // recover 1026 1009 } 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} 1012 So 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. 1013 The 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. 1034 1014 1035 1015 … … 1591 1571 1592 1572 \item 1593 lvalue to reference conversion: \lstinline[deletekeywords= lvalue]$lvalue-type cv1 T$converts to ©cv2 T &©, which allows implicitly converting variables to references.1573 lvalue to reference conversion: \lstinline[deletekeywords={lvalue}]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references. 1594 1574 \begin{cfa} 1595 1575 int x, &r = ®x®, f( int & p ); // lvalue variable (int) convert to reference (int &) … … 2700 2680 \begin{cfa}[belowskip=0pt] 2701 2681 char 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}§2682 strcpy( store, sepGet( sout ) ); 2683 sepSet( sout, "_" ); 2704 2684 sout | 1 | 2 | 3 | endl; 2705 2685 \end{cfa} … … 2708 2688 \end{cfa} 2709 2689 \begin{cfa}[belowskip=0pt] 2710 sepSet( sout, store ); §\C{// change separator back to original}§2690 sepSet( sout, store ); 2711 2691 sout | 1 | 2 | 3 | endl; 2712 2692 \end{cfa} … … 5583 5563 \Celeven prescribes the following standard header-files~\cite[\S~7.1.2]{C11} and \CFA adds to this list: 5584 5564 \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} \\ 5587 5568 \hline 5588 5569 \begin{tabular}{@{}l@{}} … … 5592 5573 \Indexc{errno.h} \\ 5593 5574 \Indexc{fenv.h} \\ 5594 \Indexc[deletekeywords=float]{float.h} \\ 5575 \Indexc{float.h} \\ 5576 \Indexc{inttypes.h} \\ 5577 \Indexc{iso646.h} \\ 5595 5578 \end{tabular} 5596 5579 & 5597 5580 \begin{tabular}{@{}l@{}} 5598 \Indexc{inttypes.h} \\5599 \Indexc{iso646.h} \\5600 5581 \Indexc{limits.h} \\ 5601 5582 \Indexc{locale.h} \\ 5602 5583 \Indexc{math.h} \\ 5603 5584 \Indexc{setjmp.h} \\ 5604 \end{tabular}5605 &5606 \begin{tabular}{@{}l@{}}5607 5585 \Indexc{signal.h} \\ 5608 5586 \Indexc{stdalign.h} \\ 5609 5587 \Indexc{stdarg.h} \\ 5610 5588 \Indexc{stdatomic.h} \\ 5611 \Indexc{stdbool.h} \\5612 \Indexc{stddef.h} \\5613 5589 \end{tabular} 5614 5590 & 5615 5591 \begin{tabular}{@{}l@{}} 5592 \Indexc{stdbool.h} \\ 5593 \Indexc{stddef.h} \\ 5616 5594 \Indexc{stdint.h} \\ 5617 5595 \Indexc{stdio.h} \\ … … 5629 5607 \Indexc{wctype.h} \\ 5630 5608 \\ 5609 \\ 5610 \\ 5631 5611 \end{tabular} 5632 5612 & … … 5634 5614 \Indexc{unistd.h} \\ 5635 5615 \Indexc{gmp.h} \\ 5616 \\ 5617 \\ 5636 5618 \\ 5637 5619 \\ … … 5673 5655 The table shows allocation routines supporting different combinations of storage-management capabilities: 5674 5656 \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 \\ 5677 5659 \hline 5678 5660 C & ©malloc© & no & no & no & no \\ … … 5681 5663 & ©memalign© & no & no & yes & no \\ 5682 5664 & ©posix_memalign© & no & no & yes & no \\ 5683 \hline5684 5665 C11 & ©aligned_alloc© & no & no & yes & no \\ 5685 \hline5686 5666 \CFA & ©alloc© & no/copy/yes & no/yes & no & yes \\ 5687 5667 & ©align_alloc© & no/yes & no & yes & yes \\
Note:
See TracChangeset
for help on using the changeset viewer.