Changeset 2296885
- Timestamp:
- Apr 14, 2018, 7:09:55 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 82df430
- Parents:
- 9ca94af
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r9ca94af r2296885 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Tue Feb 13 08:31:21201814 %% Update Count : 3 16113 %% Last Modified On : Sat Apr 14 19:04:30 2018 14 %% Update Count : 3318 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 283 283 284 284 double key = 5.0, vals[10] = { /* 10 sorted floating values */ }; 285 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); $\C{// search sorted array}$285 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); §\C{// search sorted array}§ 286 286 \end{lstlisting} 287 287 which can be augmented simply with a polymorphic, type-safe, \CFA-overloaded wrappers: … … 292 292 293 293 forall( otype T | { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t size ) { 294 T * result = bsearch( key, arr, size ); $\C{// call first version}$295 return result ? result - arr : size; } $\C{// pointer subtraction includes sizeof(T)}$296 297 double * val = bsearch( 5.0, vals, 10 ); $\C{// selection based on return type}$294 T * result = bsearch( key, arr, size ); §\C{// call first version}§ 295 return result ? result - arr : size; } §\C{// pointer subtraction includes sizeof(T)}§ 296 297 double * val = bsearch( 5.0, vals, 10 ); §\C{// selection based on return type}§ 298 298 int posn = bsearch( 5.0, vals, 10 ); 299 299 \end{lstlisting} … … 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 \Indexc[deletekeywords=inline]{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{\lstinline[deletekeywords=inline]@-fgnu89-inline@}} 356 356 Use the traditional GNU semantics for inline routines in C99 mode, which allows inline routines in header files. 357 357 \end{description} … … 506 506 507 507 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. 508 \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$.508 \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$. 509 509 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)©. 510 510 … … 524 524 525 525 526 \section{\texorpdfstring{Labelled \ LstKeywordStyle{continue} / \LstKeywordStyle{break}}{Labelled continue / break}}526 \section{\texorpdfstring{Labelled \protect\lstinline@continue@ / \protect\lstinline@break@}{Labelled continue / break}} 527 527 528 528 While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure. 529 529 Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting. 530 To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@\lstinline $continue$!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@\lstinline $break$!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85}, as in Java.530 To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@\lstinline@continue@!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@\lstinline@break@!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85}, as in Java. 531 531 For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement; 532 532 for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement. … … 613 613 \end{figure} 614 614 615 Both labelled ©continue© and ©break© are a ©goto©\index{goto@\lstinline $goto$!restricted} restricted in the following ways:615 Both labelled ©continue© and ©break© are a ©goto©\index{goto@\lstinline@goto@!restricted} restricted in the following ways: 616 616 \begin{itemize} 617 617 \item … … 629 629 630 630 631 \section{\texorpdfstring{\ LstKeywordStyle{switch}Statement}{switch Statement}}631 \section{\texorpdfstring{\protect\lstinline@switch@ Statement}{switch Statement}} 632 632 633 633 C allows a number of questionable forms for the ©switch© statement: … … 834 834 835 835 836 \section{\texorpdfstring{\ LstKeywordStyle{case}Clause}{case Clause}}836 \section{\texorpdfstring{\protect\lstinline@case@ Clause}{case Clause}} 837 837 838 838 C restricts the ©case© clause of a ©switch© statement to a single value. … … 871 871 \end{tabular} 872 872 \end{cquote} 873 In addition, two forms of subranges are allowed to specify case values: a new \CFA form and an existing GNU C form.\footnote{ 874 The GNU C form \emph{requires} spaces around the ellipse.} 875 \begin{cquote} 876 \begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}} 877 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{GNU C}} \\ 873 In addition, subranges are allowed to specify case values.\footnote{ 874 gcc has the same mechanism but awkward syntax, \lstinline@2 ...42@, because a space is required after a number, otherwise the period is a decimal point.} 878 875 \begin{cfa} 879 876 switch ( i ) { 880 case ®1~5:® 877 case ®1~5:® §\C{// 1, 2, 3, 4, 5}§ 881 878 ... 882 case ®10~15:® 879 case ®10~15:® §\C{// 10, 11, 12, 13, 14, 15}§ 883 880 ... 884 881 } 885 882 \end{cfa} 886 &887 \begin{cfa}888 switch ( i )889 case ®1 ... 5®:890 ...891 case ®10 ... 15®:892 ...893 }894 \end{cfa}895 &896 \begin{cfa}897 898 // 1, 2, 3, 4, 5899 900 // 10, 11, 12, 13, 14, 15901 902 903 \end{cfa}904 \end{tabular}905 \end{cquote}906 883 Lists of subranges are also allowed. 907 884 \begin{cfa} … … 910 887 911 888 912 \section{\texorpdfstring{\LstKeywordStyle{with} Clause / Statement}{with Clause / Statement}} 913 \label{s:WithClauseStatement} 889 \section{\texorpdfstring{\protect\lstinline@with@ Statement}{with Statement}} 890 \label{s:WithStatement} 891 892 Grouping heterogeneous data into \newterm{aggregate}s (structure/union) is a common programming practice, and an aggregate can be further organized into more complex structures, such as arrays and containers: 893 \begin{cfa} 894 struct S { §\C{// aggregate}§ 895 char c; §\C{// fields}§ 896 int i; 897 double d; 898 }; 899 S s, as[10]; 900 \end{cfa} 901 However, functions manipulating aggregates must repeat the aggregate name to access its containing fields: 902 \begin{cfa} 903 void f( S s ) { 904 `s.`c; `s.`i; `s.`d; §\C{// access containing fields}§ 905 } 906 \end{cfa} 907 which extends to multiple levels of qualification for nested aggregates. 908 A similar situation occurs in object-oriented programming, \eg \CC: 909 \begin{C++} 910 struct S { 911 char c; §\C{// fields}§ 912 int i; 913 double d; 914 void f() { §\C{// implicit ``this'' aggregate}§ 915 `this->`c; `this->`i; `this->`d; §\C{// access containing fields}§ 916 } 917 } 918 \end{C++} 919 Object-oriented nesting of member functions in a \lstinline[language=C++]@class/struct@ allows eliding \lstinline[language=C++]$this->$ because of lexical scoping. 920 However, for other aggregate parameters, qualification is necessary: 921 \begin{cfa} 922 struct T { double m, n; }; 923 int S::f( T & t ) { §\C{// multiple aggregate parameters}§ 924 c; i; d; §\C{\color{red}// this--{\textgreater}.c, this--{\textgreater}.i, this--{\textgreater}.d}§ 925 `t.`m; `t.`n; §\C{// must qualify}§ 926 } 927 \end{cfa} 928 929 To simplify the programmer experience, \CFA provides a @with@ statement (see Pascal~\cite[\S~4.F]{Pascal}) to elide aggregate qualification to fields by opening a scope containing the field identifiers. 930 Hence, the qualified fields become variables with the side-effect that it is easier to optimizing field references in a block. 931 \begin{cfa} 932 void f( S & this ) `with ( this )` { §\C{// with statement}§ 933 c; i; d; §\C{\color{red}// this.c, this.i, this.d}§ 934 } 935 \end{cfa} 936 with the generality of opening multiple aggregate-parameters: 937 \begin{cfa} 938 void f( S & s, T & t ) `with ( s, t )` { §\C{// multiple aggregate parameters}§ 939 c; i; d; §\C{\color{red}// s.c, s.i, s.d}§ 940 m; n; §\C{\color{red}// t.m, t.n}§ 941 } 942 \end{cfa} 943 944 In detail, the @with@ statement has the form: 945 \begin{cfa} 946 §\emph{with-statement}§: 947 'with' '(' §\emph{expression-list}§ ')' §\emph{compound-statement}§ 948 \end{cfa} 949 and may appear as the body of a function or nested within a function body. 950 Each expression in the expression-list provides a type and object. 951 The type must be an aggregate type. 952 (Enumerations are already opened.) 953 The object is the implicit qualifier for the open structure-fields. 954 955 All expressions in the expression list are open in parallel within the compound statement. 956 This semantic is different from Pascal, which nests the openings from left to right. 957 The difference between parallel and nesting occurs for fields with the same name and type: 958 \begin{cfa} 959 struct S { int `i`; int j; double m; } s, w; 960 struct T { int `i`; int k; int m; } t, w; 961 with ( s, t ) { 962 j + k; §\C{// unambiguous, s.j + t.k}§ 963 m = 5.0; §\C{// unambiguous, t.m = 5.0}§ 964 m = 1; §\C{// unambiguous, s.m = 1}§ 965 int a = m; §\C{// unambiguous, a = s.i }§ 966 double b = m; §\C{// unambiguous, b = t.m}§ 967 int c = s.i + t.i; §\C{// unambiguous, qualification}§ 968 (double)m; §\C{// unambiguous, cast}§ 969 } 970 \end{cfa} 971 For parallel semantics, both @s.i@ and @t.i@ are visible, so @i@ is ambiguous without qualification; 972 for nested semantics, @t.i@ hides @s.i@, so @i@ implies @t.i@. 973 \CFA's ability to overload variables means fields with the same name but different types are automatically disambiguated, eliminating most qualification when opening multiple aggregates. 974 Qualification or a cast is used to disambiguate. 975 976 There is an interesting problem between parameters and the function-body @with@, \eg: 977 \begin{cfa} 978 void ?{}( S & s, int i ) with ( s ) { §\C{// constructor}§ 979 `s.i = i;` j = 3; m = 5.5; §\C{// initialize fields}§ 980 } 981 \end{cfa} 982 Here, the assignment @s.i = i@ means @s.i = s.i@, which is meaningless, and there is no mechanism to qualify the parameter @i@, making the assignment impossible using the function-body @with@. 983 To solve this problem, parameters are treated like an initialized aggregate: 984 \begin{cfa} 985 struct Params { 986 S & s; 987 int i; 988 } params; 989 \end{cfa} 990 and implicitly opened \emph{after} a function-body open, to give them higher priority: 991 \begin{cfa} 992 void ?{}( S & s, int `i` ) with ( s ) `with( §\emph{\color{red}params}§ )` { 993 s.i = `i`; j = 3; m = 5.5; 994 } 995 \end{cfa} 996 Finally, a cast may be used to disambiguate among overload variables in a @with@ expression: 997 \begin{cfa} 998 with ( w ) { ... } §\C{// ambiguous, same name and no context}§ 999 with ( (S)w ) { ... } §\C{// unambiguous, cast}§ 1000 \end{cfa} 1001 and @with@ expressions may be complex expressions with type reference (see Section~\ref{s:References}) to aggregate: 1002 % \begin{cfa} 1003 % struct S { int i, j; } sv; 1004 % with ( sv ) { §\C{// implicit reference}§ 1005 % S & sr = sv; 1006 % with ( sr ) { §\C{// explicit reference}§ 1007 % S * sp = &sv; 1008 % with ( *sp ) { §\C{// computed reference}§ 1009 % i = 3; j = 4; §\C{\color{red}// sp--{\textgreater}i, sp--{\textgreater}j}§ 1010 % } 1011 % i = 2; j = 3; §\C{\color{red}// sr.i, sr.j}§ 1012 % } 1013 % i = 1; j = 2; §\C{\color{red}// sv.i, sv.j}§ 1014 % } 1015 % \end{cfa} 914 1016 915 1017 In \Index{object-oriented} programming, there is an implicit first parameter, often names \textbf{©self©} or \textbf{©this©}, which is elided. … … 935 1037 \CFA provides a ©with© clause/statement (see Pascal~\cite[\S~4.F]{Pascal}) to elided the "©this.©" by opening a scope containing field identifiers, changing the qualified fields into variables and giving an opportunity for optimizing qualified references. 936 1038 \begin{cfa} 937 int mem( S & this ) ®with this® { §\C{// with clause}§1039 int mem( S & this ) ®with( this )® { §\C{// with clause}§ 938 1040 i = 1; §\C{\color{red}// this.i}§ 939 1041 j = 2; §\C{\color{red}// this.j}§ … … 943 1045 \begin{cfa} 944 1046 struct T { double m, n; }; 945 int mem2( S & this1, T & this2 ) ®with this1, this2® {1047 int mem2( S & this1, T & this2 ) ®with( this1, this2 )® { 946 1048 i = 1; j = 2; 947 1049 m = 1.0; n = 2.0; … … 954 1056 struct S1 { ... } s1; 955 1057 struct S2 { ... } s2; 956 ®with s1® {§\C{// with statement}§1058 ®with( s1 )® { §\C{// with statement}§ 957 1059 // access fields of s1 without qualification 958 1060 ®with s2® { §\C{// nesting}§ … … 971 1073 struct S { int i; int j; double m; } a, c; 972 1074 struct T { int i; int k; int m } b, c; 973 ®with a, b® { 974 j + k; §\C{// unambiguous, unique names define unique types}§ 975 i; §\C{// ambiguous, same name and type}§ 976 a.i + b.i; §\C{// unambiguous, qualification defines unique names}§ 977 m; §\C{// ambiguous, same name and no context to define unique type}§ 978 m = 5.0; §\C{// unambiguous, same name and context defines unique type}§ 979 m = 1; §\C{// unambiguous, same name and context defines unique type}§ 980 } 981 ®with c® { ... } §\C{// ambiguous, same name and no context}§ 982 ®with (S)c® { ... } §\C{// unambiguous, same name and cast defines unique type}§ 983 \end{cfa} 984 1075 with( a, b ) 1076 { 1077 } 1078 \end{cfa} 1079 1080 \begin{comment} 985 1081 The components in the "with" clause 986 1082 … … 1007 1103 the "with" to be implemented because I hate having to type all those object 1008 1104 names for fields. It's a great way to drive people away from the language. 1105 \end{comment} 1009 1106 1010 1107 … … 1595 1692 1596 1693 \item 1597 lvalue to reference conversion: \lstinline[deletekeywords=lvalue] $lvalue-type cv1 T$converts to ©cv2 T &©, which allows implicitly converting variables to references.1694 lvalue to reference conversion: \lstinline[deletekeywords=lvalue]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references. 1598 1695 \begin{cfa} 1599 1696 int x, &r = ®x®, f( int & p ); // lvalue variable (int) convert to reference (int &) … … 6361 6458 6362 6459 6460 \section{Time} 6461 \label{s:TimeLib} 6462 6463 6464 %\subsection{\texorpdfstring{\protect\lstinline@Duration@}{Duration}} 6465 \subsection{\texorpdfstring{\LstKeywordStyle{\textmd{Duration}}}{Duration}} 6466 \label{s:Duration} 6467 6468 \leavevmode 6469 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 6470 struct Duration { 6471 int64_t tv; §\C{// nanoseconds}§ 6472 }; 6473 6474 void ?{}( Duration & dur ); 6475 void ?{}( Duration & dur, zero_t ); 6476 6477 Duration ?=?( Duration & dur, zero_t ); 6478 6479 Duration +?( Duration rhs ); 6480 Duration ?+?( Duration & lhs, Duration rhs ); 6481 Duration ?+=?( Duration & lhs, Duration rhs ); 6482 6483 Duration -?( Duration rhs ); 6484 Duration ?-?( Duration & lhs, Duration rhs ); 6485 Duration ?-=?( Duration & lhs, Duration rhs ); 6486 6487 Duration ?*?( Duration lhs, int64_t rhs ); 6488 Duration ?*?( int64_t lhs, Duration rhs ); 6489 Duration ?*=?( Duration & lhs, int64_t rhs ); 6490 6491 int64_t ?/?( Duration lhs, Duration rhs ); 6492 Duration ?/?( Duration lhs, int64_t rhs ); 6493 Duration ?/=?( Duration & lhs, int64_t rhs ); 6494 double div( Duration lhs, Duration rhs ); 6495 6496 Duration ?%?( Duration lhs, Duration rhs ); 6497 Duration ?%=?( Duration & lhs, Duration rhs ); 6498 6499 _Bool ?==?( Duration lhs, Duration rhs ); 6500 _Bool ?!=?( Duration lhs, Duration rhs ); 6501 _Bool ?<? ( Duration lhs, Duration rhs ); 6502 _Bool ?<=?( Duration lhs, Duration rhs ); 6503 _Bool ?>? ( Duration lhs, Duration rhs ); 6504 _Bool ?>=?( Duration lhs, Duration rhs ); 6505 6506 _Bool ?==?( Duration lhs, zero_t ); 6507 _Bool ?!=?( Duration lhs, zero_t ); 6508 _Bool ?<? ( Duration lhs, zero_t ); 6509 _Bool ?<=?( Duration lhs, zero_t ); 6510 _Bool ?>? ( Duration lhs, zero_t ); 6511 _Bool ?>=?( Duration lhs, zero_t ); 6512 6513 Duration abs( Duration rhs ); 6514 6515 forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Duration dur ); 6516 6517 Duration ?`ns( int64_t nsec ); 6518 Duration ?`us( int64_t usec ); 6519 Duration ?`ms( int64_t msec ); 6520 Duration ?`s( int64_t sec ); 6521 Duration ?`s( double sec ); 6522 Duration ?`m( int64_t min ); 6523 Duration ?`m( double min ); 6524 Duration ?`h( int64_t hours ); 6525 Duration ?`h( double hours ); 6526 Duration ?`d( int64_t days ); 6527 Duration ?`d( double days ); 6528 Duration ?`w( int64_t weeks ); 6529 Duration ?`w( double weeks ); 6530 6531 int64_t ?`ns( Duration dur ); 6532 int64_t ?`us( Duration dur ); 6533 int64_t ?`ms( Duration dur ); 6534 int64_t ?`s( Duration dur ); 6535 int64_t ?`m( Duration dur ); 6536 int64_t ?`h( Duration dur ); 6537 int64_t ?`d( Duration dur ); 6538 int64_t ?`w( Duration dur ); 6539 \end{cfa} 6540 6541 6542 %\subsection{\texorpdfstring{\protect\lstinline@\timeval@}{timeval}} 6543 \subsection{\texorpdfstring{\LstKeywordStyle{\textmd{timeval}}}{timeval}} 6544 \label{s:timeval} 6545 6546 \leavevmode 6547 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 6548 void ?{}( timeval & t ); 6549 void ?{}( timeval & t, time_t sec, suseconds_t usec ); 6550 void ?{}( timeval & t, time_t sec ); 6551 void ?{}( timeval & t, zero_t ); 6552 void ?{}( timeval & t, Time time ); 6553 6554 timeval ?=?( timeval & t, zero_t ); 6555 timeval ?+?( timeval & lhs, timeval rhs ); 6556 timeval ?-?( timeval & lhs, timeval rhs ); 6557 _Bool ?==?( timeval lhs, timeval rhs ); 6558 _Bool ?!=?( timeval lhs, timeval rhs ); 6559 \end{cfa} 6560 6561 6562 \subsection{\texorpdfstring{\protect\lstinline@timespec@}{timespec}} 6563 \label{s:timespec} 6564 6565 \leavevmode 6566 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 6567 void ?{}( timespec & t ); 6568 void ?{}( timespec & t, time_t sec, __syscall_slong_t nsec ); 6569 void ?{}( timespec & t, time_t sec ); 6570 void ?{}( timespec & t, zero_t ); 6571 void ?{}( timespec & t, Time time ); 6572 6573 timespec ?=?( timespec & t, zero_t ); 6574 timespec ?+?( timespec & lhs, timespec rhs ); 6575 timespec ?-?( timespec & lhs, timespec rhs ); 6576 _Bool ?==?( timespec lhs, timespec rhs ); 6577 _Bool ?!=?( timespec lhs, timespec rhs ); 6578 \end{cfa} 6579 6580 6581 \subsection{\texorpdfstring{\protect\lstinline@itimerval@}{itimerval}} 6582 \label{s:itimerval} 6583 6584 \leavevmode 6585 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 6586 void ?{}( itimerval & itv, Duration alarm ); 6587 void ?{}( itimerval & itv, Duration alarm, Duration interval ); 6588 \end{cfa} 6589 6590 6591 \subsection{\texorpdfstring{\protect\lstinline@Time@}{Time}} 6592 \label{s:Time} 6593 6594 \leavevmode 6595 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 6596 struct Time { 6597 uint64_t tv; §\C{// nanoseconds since UNIX epoch}§ 6598 }; 6599 6600 void ?{}( Time & time ); 6601 void ?{}( Time & time, zero_t ); 6602 void ?{}( Time & time, int year, int month = 0, int day = 0, int hour = 0, int min = 0, int sec = 0, int nsec = 0 ); 6603 Time ?=?( Time & time, zero_t ); 6604 6605 void ?{}( Time & time, timeval t ); 6606 Time ?=?( Time & time, timeval t ); 6607 6608 void ?{}( Time & time, timespec t ); 6609 Time ?=?( Time & time, timespec t ); 6610 6611 Time ?+?( Time & lhs, Duration rhs ) { return (Time)@{ lhs.tv + rhs.tv }; } 6612 Time ?+?( Duration lhs, Time rhs ) { return rhs + lhs; } 6613 Time ?+=?( Time & lhs, Duration rhs ) { lhs = lhs + rhs; return lhs; } 6614 6615 Duration ?-?( Time lhs, Time rhs ) { return (Duration)@{ lhs.tv - rhs.tv }; } 6616 Time ?-?( Time lhs, Duration rhs ) { return (Time)@{ lhs.tv - rhs.tv }; } 6617 Time ?-=?( Time & lhs, Duration rhs ) { lhs = lhs - rhs; return lhs; } 6618 _Bool ?==?( Time lhs, Time rhs ) { return lhs.tv == rhs.tv; } 6619 _Bool ?!=?( Time lhs, Time rhs ) { return lhs.tv != rhs.tv; } 6620 _Bool ?<?( Time lhs, Time rhs ) { return lhs.tv < rhs.tv; } 6621 _Bool ?<=?( Time lhs, Time rhs ) { return lhs.tv <= rhs.tv; } 6622 _Bool ?>?( Time lhs, Time rhs ) { return lhs.tv > rhs.tv; } 6623 _Bool ?>=?( Time lhs, Time rhs ) { return lhs.tv >= rhs.tv; } 6624 6625 forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time ); 6626 6627 char * yy_mm_dd( Time time, char * buf ); 6628 char * ?`ymd( Time time, char * buf ) { // short form 6629 return yy_mm_dd( time, buf ); 6630 } // ymd 6631 6632 char * mm_dd_yy( Time time, char * buf ); 6633 char * ?`mdy( Time time, char * buf ) { // short form 6634 return mm_dd_yy( time, buf ); 6635 } // mdy 6636 6637 char * dd_mm_yy( Time time, char * buf ); 6638 char * ?`dmy( Time time, char * buf ) { // short form 6639 return dd_mm_yy( time, buf );; 6640 } // dmy 6641 6642 size_t strftime( char * buf, size_t size, const char * fmt, Time time ); 6643 \end{cfa} 6644 6645 6646 \section{Clock} 6647 6648 \subsection{C time} 6649 \label{s:Ctime} 6650 6651 \leavevmode 6652 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 6653 char * ctime( time_t tp ); 6654 char * ctime_r( time_t tp, char * buf ); 6655 tm * gmtime( time_t tp ); 6656 tm * gmtime_r( time_t tp, tm * result ); 6657 tm * localtime( time_t tp ); 6658 tm * localtime_r( time_t tp, tm * result ); 6659 \end{cfa} 6660 6661 6662 %\subsection{\texorpdfstring{\protect\lstinline@Clock@}{Clock}} 6663 \subsection{\texorpdfstring{\LstKeywordStyle{\textmd{Clock}}}{Clock}} 6664 \label{s:Clock} 6665 6666 \leavevmode 6667 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 6668 struct Clock { 6669 Duration offset; §\C{// for virtual clock: contains offset from real-time}§ 6670 int clocktype; §\C{// implementation only -1 (virtual), CLOCK\_REALTIME}§ 6671 }; 6672 6673 void resetClock( Clock & clk ); 6674 void resetClock( Clock & clk, Duration adj ); 6675 void ?{}( Clock & clk ); 6676 void ?{}( Clock & clk, Duration adj ); 6677 Duration getRes(); 6678 Time getTimeNsec(); §\C{// with nanoseconds}§ 6679 Time getTime(); §\C{// without nanoseconds}§ 6680 Time getTime( Clock & clk ); 6681 Time ?()( Clock & clk ); 6682 timeval getTime( Clock & clk ); 6683 tm getTime( Clock & clk ); 6684 \end{cfa} 6685 6686 6363 6687 \section{Multi-precision Integers} 6364 6688 \label{s:MultiPrecisionIntegers} … … 6658 6982 \end{cfa} 6659 6983 6660 6661 6984 \bibliographystyle{plain} 6662 6985 \bibliography{pl}
Note: See TracChangeset
for help on using the changeset viewer.