Changes in doc/user/user.tex [d92ff4a:200fcb3]
- File:
-
- 1 edited
-
doc/user/user.tex (modified) (52 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
rd92ff4a r200fcb3 1 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 %% 2 %% 3 3 %% Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo 4 4 %% 5 5 %% The contents of this file are covered under the licence agreement in the 6 6 %% file "LICENCE" distributed with Cforall. 7 %% 8 %% user.tex -- 9 %% 7 %% 8 %% user.tex -- 9 %% 10 10 %% Author : Peter A. Buhr 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : T hu Jul 26 17:29:05201814 %% Update Count : 3 36613 %% Last Modified On : Tue Dec 11 23:19:26 2018 14 %% Update Count : 3400 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 72 72 73 73 % Names used in the document. 74 \newcommand{\Version}{\input{ ../../version}}74 \newcommand{\Version}{\input{build/version}} 75 75 \newcommand{\Textbf}[2][red]{{\color{#1}{\textbf{#2}}}} 76 76 \newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}} … … 178 178 int main( void ) { 179 179 int x = 0, y = 1, z = 2; 180 ®sout | x | y | z | endl;®§\indexc{sout}§180 ®sout | x | y | z;®§\indexc{sout}§ 181 181 } 182 182 \end{cfa} … … 210 210 Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction. 211 211 For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is usually the only language of choice. 212 The TIOBE index~\cite{TIOBE} for July 2018 ranks the top 5 most \emph{popular} programming languages as:\Index*{Java} 16\%, C 14\%, \Index*[C++]{\CC{}} 7.5\%, Python 6\%, Visual Basic 4\% = 47.5\%, where the next 50 languages are less than 4\% each, with a long tail.212 The TIOBE index~\cite{TIOBE} for July 2018 ranks the top five most \emph{popular} programming languages as \Index*{Java} 16\%, C 14\%, \Index*[C++]{\CC{}} 7.5\%, Python 6\%, Visual Basic 4\% = 47.5\%, where the next 50 languages are less than 4\% each, with a long tail. 213 213 The top 3 rankings over the past 30 years are: 214 214 \begin{center} … … 351 351 The 2011 C standard plus GNU extensions. 352 352 \item 353 \Indexc[deletekeywords=inline]{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{\lstinline[deletekeywords=inline] @-fgnu89-inline@}}353 \Indexc[deletekeywords=inline]{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{\lstinline[deletekeywords=inline]$-fgnu89-inline$}} 354 354 Use the traditional GNU semantics for inline routines in C11 mode, which allows inline routines in header files. 355 355 \end{description} … … 430 430 #endif 431 431 \end{cfa} 432 which conditionally includes the correct header file, if the program is compiled using \Indexc{gcc} or \Indexc{cfa}. 432 which conditionally includes the correct header file, if the program is compiled using \Indexc{gcc} or \Indexc{cfa}. 433 433 434 434 … … 455 455 #endif 456 456 457 ®#include_next <bfdlink.h> §\C{// must have internal check for multiple expansion}§457 ®#include_next <bfdlink.h> §\C{// must have internal check for multiple expansion}§ 458 458 ® 459 459 #if defined( with ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§ … … 504 504 505 505 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. 506 \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$.506 \CFA extends the basic operators with the exponentiation operator ©?\?©\index{?\\?@©?\?©} and ©?\=?©\index{?\\=?@©\=?©}, as in, ©x \ y© and ©x \= y©, which means $x^y$ and $x \leftarrow x^y$. 507 507 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)©. 508 508 … … 513 513 Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative. 514 514 \begin{cfa} 515 sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) | endl;515 sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi); 516 516 256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i 517 517 \end{cfa} 518 Parenthesis are necessary for the complex constants or the expression is parsed as ©1.0f+(2.0fi \ 3.0f)+2.0fi©.518 Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©. 519 519 The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation versions are available. 520 520 For returning an integral value, the user type ©T© must define multiplication, ©*©, and one, ©1©; … … 527 527 528 528 529 %\subsection{\texorpdfstring{\protect\lstinline@if@ Statement}{if Statement}} 530 \subsection{\texorpdfstring{\LstKeywordStyle{if} Statement}{if Statement}} 531 532 The ©if© expression allows declarations, similar to ©for© declaration expression: 533 \begin{cfa} 534 if ( int x = f() ) ... §\C{// x != 0}§ 535 if ( int x = f(), y = g() ) ... §\C{// x != 0 \&\& y != 0}§ 536 if ( int x = f(), y = g(); ®x < y® ) ... §\C{// relational expression}§ 537 \end{cfa} 538 Unless a relational expression is specified, each variable is compared not equal to 0, which is the standard semantics for the ©if© expression, and the results are combined using the logical ©&&© operator.\footnote{\CC only provides a single declaration always compared not equal to 0.} 529 %\subsection{\texorpdfstring{\protect\lstinline@if@/\protect\lstinline@while@ Statement}{if Statement}} 530 \subsection{\texorpdfstring{\LstKeywordStyle{if}/\LstKeywordStyle{while} Statement}{if/while Statement}} 531 532 The ©if©/©while© expression allows declarations, similar to ©for© declaration expression. 533 (Does not make sense for ©do©-©while©.) 534 \begin{cfa} 535 if ( ®int x = f()® ) ... §\C{// x != 0}§ 536 if ( ®int x = f(), y = g()® ) ... §\C{// x != 0 \&\& y != 0}§ 537 if ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§ 538 if ( ®struct S { int i; } x = { f() }; x.i < 4® ) §\C{// relational expression}§ 539 540 while ( ®int x = f()® ) ... §\C{// x != 0}§ 541 while ( ®int x = f(), y = g()® ) ... §\C{// x != 0 \&\& y != 0}§ 542 while ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§ 543 while ( ®struct S { int i; } x = { f() }; x.i < 4® ) ... §\C{// relational expression}§ 544 \end{cfa} 545 Unless a relational expression is specified, each variable is compared not equal to 0, which is the standard semantics for the ©if©/©while© expression, and the results are combined using the logical ©&&© operator.\footnote{\CC only provides a single declaration always compared not equal to 0.} 539 546 The scope of the declaration(s) is local to the @if@ statement but exist within both the ``then'' and ``else'' clauses. 547 548 549 \subsection{Loop Control} 550 551 The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges. 552 An empty conditional implies ©1©. 553 The up-to range ©~©\index{~@©~©} means exclusive range [M,N); 554 the up-to range ©~=©\index{~=@©~=©} means inclusive range [M,N]. 555 The down-to range ©-~©\index{-~@©-~©} means exclusive range [N,M); 556 the down-to range ©-~=©\index{-~=@©-~=©} means inclusive range [N,M]. 557 ©0© is the implicit start value; 558 ©1© is the implicit increment value. 559 The up-to range uses ©+=© for increment; 560 the down-to range uses ©-=© for decrement. 561 The loop index is polymorphic in the type of the start value or comparison value when start is implicitly ©0©. 562 \begin{cquote} 563 \begin{tabular}{@{}ll|l@{}} 564 \multicolumn{2}{c|}{loop control} & \multicolumn{1}{c}{output} \\ 565 \hline 566 \begin{cfa} 567 while ®()® { sout | "empty"; break; } 568 do { sout | "empty"; break; } while ®()®; 569 for ®()® { sout | "empty"; break; } 570 for ( ®0® ) { sout | "A"; } 571 for ( ®1® ) { sout | "A"; } 572 for ( ®10® ) { sout | "A"; } 573 for ( ®1 ~= 10 ~ 2® ) { sout | "B"; } 574 for ( ®10 -~= 1 ~ 2® ) { sout | "C"; } 575 for ( ®0.5 ~ 5.5® ) { sout | "D"; } 576 for ( ®5.5 -~ 0.5® ) { sout | "E"; } 577 for ( ®i; 10® ) { sout | i; } 578 for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; } 579 for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; } 580 for ( ®i; 0.5 ~ 5.5® ) { sout | i; } 581 for ( ®i; 5.5 -~ 0.5® ) { sout | i; } 582 for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; } 583 for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; } 584 enum { N = 10 }; 585 for ( ®N® ) { sout | "N"; } 586 for ( ®i; N® ) { sout | i; } 587 for ( ®i; N -~ 0® ) { sout | i; } 588 const int start = 3, comp = 10, inc = 2; 589 for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; } 590 \end{cfa} 591 & 592 \begin{cfa} 593 sout | nl; 594 sout | nl; 595 sout | nl; 596 sout | "zero" | nl; 597 sout | nl; 598 sout | nl; 599 sout | nl; 600 sout | nl; 601 sout | nl; 602 sout | nl; 603 sout | nl; 604 sout | nl; 605 sout | nl; 606 sout | nl; 607 sout | nl; 608 sout | nl; 609 sout | nl | nl; 610 611 sout | nl; 612 sout | nl; 613 sout | nl | nl; 614 615 sout | nl; 616 \end{cfa} 617 & 618 \begin{cfa} 619 empty 620 empty 621 empty 622 zero 623 A 624 A A A A A A A A A A 625 B B B B B 626 C C C C C 627 D D D D D 628 E E E E E 629 0 1 2 3 4 5 6 7 8 9 630 1 3 5 7 9 631 10 8 6 4 2 632 0.5 1.5 2.5 3.5 4.5 633 5.5 4.5 3.5 2.5 1.5 634 2 4 6 8 10 635 10 8 6 4 2 636 637 N N N N N N N N N N 638 0 1 2 3 4 5 6 7 8 9 639 10 9 8 7 6 5 4 3 2 1 640 641 3 6 9 642 \end{cfa} 643 \end{tabular} 644 \end{cquote} 540 645 541 646 … … 800 905 801 906 907 % for () => for ( ;; ) 908 % for ( 10 - t ) => for ( typeof(10 - t) ? = 0 ; ? < 10 - t; ? += 1 ) // using 0 and 1 909 % for ( i ; 10 - t ) => for ( typeof(10 - t) i = 0 ; i < 10 - t; i += 1 ) // using 0 and 1 910 % for ( T i ; 10 - t ) => for ( T i = 0 ; i < 10 - t; i += 1 ) // using 0 and 1 911 % for ( 3~9 ) => for ( int ? = 3 ; ? < 9; ? += 1 ) // using 1 912 % for ( i ; 3~9 ) => for ( int i = 3 ; i < 9; i += 1 ) // using 1 913 % for ( T i ; 3~9 ) => for ( T i = 3 ; i < 9; i += 1 ) // using 1 914 915 802 916 %\subsection{\texorpdfstring{Labelled \protect\lstinline@continue@ / \protect\lstinline@break@}{Labelled continue / break}} 803 917 \subsection{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break} Statement}{Labelled continue / break Statement}} … … 805 919 While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure. 806 920 Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting. 807 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.921 To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@©continue©!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@©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. 808 922 For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement; 809 923 for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement. … … 890 1004 \end{figure} 891 1005 892 Both labelled ©continue© and ©break© are a ©goto©\index{goto@ \lstinline@goto@!restricted} restricted in the following ways:1006 Both labelled ©continue© and ©break© are a ©goto©\index{goto@©goto©!restricted} restricted in the following ways: 893 1007 \begin{itemize} 894 1008 \item … … 1447 1561 \end{cfa} 1448 1562 Algol68 infers the following dereferencing ©*p2 = *p1 + x©, because adding the arbitrary integer value in ©x© to the address of ©p1© and storing the resulting address into ©p2© is an unlikely operation. 1449 Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices. 1563 Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices. 1450 1564 1451 1565 Rather than inferring dereference, most programming languages pick one implicit dereferencing semantics, and the programmer explicitly indicates the other to resolve address-duality. … … 2282 2396 struct T t; 2283 2397 } s; 2284 2398 2285 2399 2286 2400 … … 2345 2459 int bar( int p ) { 2346 2460 ®i® += 1; §\C{// dependent on local variable}§ 2347 sout | ®i® | endl;2461 sout | ®i®; 2348 2462 } 2349 2463 return bar; §\C{// undefined because of local dependence}§ … … 2351 2465 int main() { 2352 2466 * [int]( int ) fp = foo(); §\C{// int (* fp)( int )}§ 2353 sout | fp( 3 ) | endl;2354 } 2355 \end{cfa} 2356 because 2467 sout | fp( 3 ); 2468 } 2469 \end{cfa} 2470 because 2357 2471 2358 2472 Currently, there are no \Index{lambda} expressions, \ie unnamed routines because routine names are very important to properly select the correct routine. … … 3117 3231 \begin{cfa} 3118 3232 int x = 1, y = 2, z = 3; 3119 sout | x ®|® y ®|® z | endl;3233 sout | x ®|® y ®|® z; 3120 3234 \end{cfa} 3121 3235 & … … 3138 3252 \begin{cfa} 3139 3253 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ]; 3140 sout | t1 | t2 | endl;§\C{// print tuples}§3254 sout | t1 | t2; §\C{// print tuples}§ 3141 3255 \end{cfa} 3142 3256 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3150 3264 & 3151 3265 \begin{cfa} 3152 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;3266 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2); 3153 3267 \end{cfa} 3154 3268 \\ … … 3176 3290 A separator does not appear at the start or end of a line. 3177 3291 \begin{cfa}[belowskip=0pt] 3178 sout | 1 | 2 | 3 | endl;3292 sout | 1 | 2 | 3; 3179 3293 \end{cfa} 3180 3294 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3185 3299 A separator does not appear before or after a character literal or variable. 3186 3300 \begin{cfa} 3187 sout | '1' | '2' | '3' | endl;3301 sout | '1' | '2' | '3'; 3188 3302 123 3189 3303 \end{cfa} … … 3192 3306 A separator does not appear before or after a null (empty) C string. 3193 3307 \begin{cfa} 3194 sout | 1 | "" | 2 | "" | 3 | endl;3308 sout | 1 | "" | 2 | "" | 3; 3195 3309 123 3196 3310 \end{cfa} … … 3202 3316 \begin{cfa}[mathescape=off] 3203 3317 sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥" 3204 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl;3318 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10; 3205 3319 \end{cfa} 3206 3320 %$ … … 3216 3330 \begin{cfa}[belowskip=0pt] 3217 3331 sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x" 3218 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl;3332 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x"; 3219 3333 \end{cfa} 3220 3334 \begin{cfa}[basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3226 3340 A seperator does not appear before or after a C string begining/ending with the \Index*{ASCII} quote or whitespace characters: \lstinline[basicstyle=\tt,showspaces=true]@`'": \t\v\f\r\n@ 3227 3341 \begin{cfa}[belowskip=0pt] 3228 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl;3342 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx"; 3229 3343 \end{cfa} 3230 3344 \begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt] … … 3235 3349 If a space is desired before or after one of the special string start/end characters, simply insert a space. 3236 3350 \begin{cfa}[belowskip=0pt] 3237 sout | "x (§\color{red}\texttt{\textvisiblespace}§" | 1 | "§\color{red}\texttt{\textvisiblespace}§) x" | 2 | "§\color{red}\texttt{\textvisiblespace}§, x" | 3 | "§\color{red}\texttt{\textvisiblespace}§:x:§\color{red}\texttt{\textvisiblespace}§" | 4 | endl;3351 sout | "x (§\color{red}\texttt{\textvisiblespace}§" | 1 | "§\color{red}\texttt{\textvisiblespace}§) x" | 2 | "§\color{red}\texttt{\textvisiblespace}§, x" | 3 | "§\color{red}\texttt{\textvisiblespace}§:x:§\color{red}\texttt{\textvisiblespace}§" | 4; 3238 3352 \end{cfa} 3239 3353 \begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt] … … 3252 3366 \begin{cfa}[mathescape=off,belowskip=0pt] 3253 3367 sepSet( sout, ", $" ); §\C{// set separator from " " to ", \$"}§ 3254 sout | 1 | 2 | 3 | " \"" | ®sep® | "\"" | endl;3368 sout | 1 | 2 | 3 | " \"" | ®sep® | "\""; 3255 3369 \end{cfa} 3256 3370 %$ … … 3261 3375 \begin{cfa}[belowskip=0pt] 3262 3376 sepSet( sout, " " ); §\C{// reset separator to " "}§ 3263 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl;3377 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\""; 3264 3378 \end{cfa} 3265 3379 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3271 3385 strcpy( store, sepGet( sout ) ); §\C{// copy current separator}§ 3272 3386 sepSet( sout, "_" ); §\C{// change separator to underscore}§ 3273 sout | 1 | 2 | 3 | endl;3387 sout | 1 | 2 | 3; 3274 3388 \end{cfa} 3275 3389 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3278 3392 \begin{cfa}[belowskip=0pt] 3279 3393 sepSet( sout, store ); §\C{// change separator back to original}§ 3280 sout | 1 | 2 | 3 | endl;3394 sout | 1 | 2 | 3; 3281 3395 \end{cfa} 3282 3396 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3289 3403 \begin{cfa}[belowskip=0pt] 3290 3404 sepSetTuple( sout, " " ); §\C{// set tuple separator from ", " to " "}§ 3291 sout | t1 | t2 | " \"" | ®sepTuple® | "\"" | endl;3405 sout | t1 | t2 | " \"" | ®sepTuple® | "\""; 3292 3406 \end{cfa} 3293 3407 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3296 3410 \begin{cfa}[belowskip=0pt] 3297 3411 sepSetTuple( sout, ", " ); §\C{// reset tuple separator to ", "}§ 3298 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl;3412 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\""; 3299 3413 \end{cfa} 3300 3414 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3306 3420 Manipulators \Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} \emph{globally} toggle printing the separator, \ie the seperator is adjusted with respect to all subsequent printed items. 3307 3421 \begin{cfa}[belowskip=0pt] 3308 sout | sepDisable | 1 | 2 | 3 | endl;§\C{// globally turn off implicit separator}§3422 sout | sepDisable | 1 | 2 | 3; §\C{// globally turn off implicit separator}§ 3309 3423 \end{cfa} 3310 3424 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3312 3426 \end{cfa} 3313 3427 \begin{cfa}[belowskip=0pt] 3314 sout | sepEnable | 1 | 2 | 3 | endl; §\C{// globally turn on implicit separator}§3428 sout | sepEnable | 1 | 2 | 3; §\C{// globally turn on implicit separator}§ 3315 3429 \end{cfa} 3316 3430 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3321 3435 Manipulators \Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} \emph{locally} toggle printing the separator, \ie the seperator is adjusted only with respect to the next printed item. 3322 3436 \begin{cfa}[belowskip=0pt] 3323 sout | 1 | sepOff | 2 | 3 | endl; §\C{// locally turn off implicit separator}§3437 sout | 1 | sepOff | 2 | 3; §\C{// locally turn off implicit separator}§ 3324 3438 \end{cfa} 3325 3439 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3327 3441 \end{cfa} 3328 3442 \begin{cfa}[belowskip=0pt] 3329 sout | sepDisable | 1 | sepOn | 2 | 3 | endl; §\C{// locally turn on implicit separator}§3443 sout | sepDisable | 1 | sepOn | 2 | 3; §\C{// locally turn on implicit separator}§ 3330 3444 \end{cfa} 3331 3445 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3334 3448 The tuple separator also responses to being turned on and off. 3335 3449 \begin{cfa}[belowskip=0pt] 3336 sout | t1 | sepOff | t2 | endl; §\C{// locally turn on/off implicit separator}§3450 sout | t1 | sepOff | t2; §\C{// locally turn on/off implicit separator}§ 3337 3451 \end{cfa} 3338 3452 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3342 3456 use ©sep© to accomplish this functionality. 3343 3457 \begin{cfa}[belowskip=0pt] 3344 sout | sepOn | 1 | 2 | 3 | sepOn | endl; §\C{// sepOn does nothing at start/end of line}§3458 sout | sepOn | 1 | 2 | 3 | sepOn; §\C{// sepOn does nothing at start/end of line}§ 3345 3459 \end{cfa} 3346 3460 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3348 3462 \end{cfa} 3349 3463 \begin{cfa}[belowskip=0pt] 3350 sout | sep | 1 | 2 | 3 | sep | endl; §\C{// use sep to print separator at start/end of line}§3464 sout | sep | 1 | 2 | 3 | sep ; §\C{// use sep to print separator at start/end of line}§ 3351 3465 \end{cfa} 3352 3466 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3361 3475 int main( void ) { 3362 3476 int x = 1, y = 2, z = 3; 3363 sout | x | y | z | endl;3477 sout | x | y | z; 3364 3478 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ]; 3365 sout | t1 | t2 | endl; // print tuples3366 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;3367 sout | 1 | 2 | 3 | endl;3368 sout | '1' | '2' | '3' | endl;3369 sout | 1 | "" | 2 | "" | 3 | endl;3479 sout | t1 | t2; // print tuples 3480 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2); 3481 sout | 1 | 2 | 3; 3482 sout | '1' | '2' | '3'; 3483 sout | 1 | "" | 2 | "" | 3; 3370 3484 sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥" 3371 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl;3485 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10; 3372 3486 sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x" 3373 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl;3374 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl;3375 sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl;3487 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x"; 3488 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx"; 3489 sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4; 3376 3490 3377 3491 sepSet( sout, ", $" ); // set separator from " " to ", $" 3378 sout | 1 | 2 | 3 | " \"" | sep | "\"" | endl;3492 sout | 1 | 2 | 3 | " \"" | sep | "\""; 3379 3493 sepSet( sout, " " ); // reset separator to " " 3380 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;3494 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\""; 3381 3495 3382 3496 char store[sepSize]; 3383 3497 strcpy( store, sepGet( sout ) ); 3384 3498 sepSet( sout, "_" ); 3385 sout | 1 | 2 | 3 | endl;3499 sout | 1 | 2 | 3; 3386 3500 sepSet( sout, store ); 3387 sout | 1 | 2 | 3 | endl;3501 sout | 1 | 2 | 3; 3388 3502 3389 3503 sepSetTuple( sout, " " ); // set tuple separator from ", " to " " 3390 sout | t1 | t2 | " \"" | sepTuple | "\"" | endl;3504 sout | t1 | t2 | " \"" | sepTuple | "\""; 3391 3505 sepSetTuple( sout, ", " ); // reset tuple separator to ", " 3392 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl;3393 3394 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separator3395 sout | sepEnable | 1 | 2 | 3 | endl; // globally turn on implicit separator3396 3397 sout | 1 | sepOff | 2 | 3 | endl; // locally turn on implicit separator3398 sout | sepDisable | 1 | sepOn | 2 | 3 | endl; // globally turn off implicit separator3506 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\""; 3507 3508 sout | sepDisable | 1 | 2 | 3; // globally turn off implicit separator 3509 sout | sepEnable | 1 | 2 | 3; // globally turn on implicit separator 3510 3511 sout | 1 | sepOff | 2 | 3; // locally turn on implicit separator 3512 sout | sepDisable | 1 | sepOn | 2 | 3; // globally turn off implicit separator 3399 3513 sout | sepEnable; 3400 sout | t1 | sepOff | t2 | endl; // locally turn on/off implicit separator3401 3402 sout | sepOn | 1 | 2 | 3 | sepOn | endl; // sepOn does nothing at start/end of line3403 sout | sep | 1 | 2 | 3 | sep | endl; // use sep to print separator at start/end of line3514 sout | t1 | sepOff | t2; // locally turn on/off implicit separator 3515 3516 sout | sepOn | 1 | 2 | 3 | sepOn ; // sepOn does nothing at start/end of line 3517 sout | sep | 1 | 2 | 3 | sep ; // use sep to print separator at start/end of line 3404 3518 } 3405 3519 … … 4066 4180 Fibonacci f1, f2; 4067 4181 for ( int i = 1; i <= 10; i += 1 ) { 4068 sout | next( &f1 ) | ' ' | next( &f2 ) | endl;4182 sout | next( &f1 ) | ' ' | next( &f2 ); 4069 4183 } // for 4070 4184 } … … 4132 4246 MyThread f[4]; 4133 4247 } 4134 sout | global.value | endl;4248 sout | global.value; 4135 4249 } 4136 4250 \end{cfa} … … 4210 4324 void main( First * this ) { 4211 4325 for ( int i = 0; i < 10; i += 1 ) { 4212 sout | "First : Suspend No." | i + 1 | endl;4326 sout | "First : Suspend No." | i + 1; 4213 4327 yield(); 4214 4328 } … … 4219 4333 wait( this->lock ); 4220 4334 for ( int i = 0; i < 10; i += 1 ) { 4221 sout | "Second : Suspend No." | i + 1 | endl;4335 sout | "Second : Suspend No." | i + 1; 4222 4336 yield(); 4223 4337 } … … 4226 4340 int main( void ) { 4227 4341 signal_once lock; 4228 sout | "User main begin" | endl;4342 sout | "User main begin"; 4229 4343 { 4230 4344 processor p; … … 4234 4348 } 4235 4349 } 4236 sout | "User main end" | endl;4350 sout | "User main end"; 4237 4351 } 4238 4352 \end{cfa} … … 4931 5045 void ?{}( Line * l ) { 4932 5046 l->lnth = 0.0; 4933 sout | "default" | endl;5047 sout | "default"; 4934 5048 } 4935 5049 … … 4938 5052 void ?{}( Line * l, float lnth ) { 4939 5053 l->lnth = lnth; 4940 sout | "lnth" | l->lnth | endl;5054 sout | "lnth" | l->lnth; 4941 5055 4942 5056 } … … 4944 5058 // destructor 4945 5059 void ^?() { 4946 sout | "destroyed" | endl;5060 sout | "destroyed"; 4947 5061 l.lnth = 0.0; 4948 5062 } … … 5690 5804 In particular, output of ©char© variable now print a character rather than the decimal ASCII value of the character. 5691 5805 \begin{cfa} 5692 sout | 'x' | " " | (int)'x' | endl;5806 sout | 'x' | " " | (int)'x'; 5693 5807 x 120 5694 5808 \end{cfa} … … 6920 7034 #include <gmp>§\indexc{gmp}§ 6921 7035 int main( void ) { 6922 sout | "Factorial Numbers" | endl;7036 sout | "Factorial Numbers"; 6923 7037 Int fact = 1; 6924 7038 6925 sout | 0 | fact | endl;7039 sout | 0 | fact; 6926 7040 for ( unsigned int i = 1; i <= 40; i += 1 ) { 6927 7041 fact *= i; 6928 sout | i | fact | endl;7042 sout | i | fact; 6929 7043 } 6930 7044 }
Note:
See TracChangeset
for help on using the changeset viewer.