Changes in doc/user/user.tex [200fcb3:d92ff4a]
- File:
-
- 1 edited
-
doc/user/user.tex (modified) (52 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r200fcb3 rd92ff4a 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 ue Dec 11 23:19:26201814 %% Update Count : 3 40013 %% Last Modified On : Thu Jul 26 17:29:05 2018 14 %% Update Count : 3366 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 72 72 73 73 % Names used in the document. 74 \newcommand{\Version}{\input{ build/version}}74 \newcommand{\Version}{\input{../../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 ;®§\indexc{sout}§180 ®sout | x | y | z | endl;®§\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 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.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. 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{?\\?@ ©?\?©} and ©?\=?©\index{?\\=?@©\=?©}, 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{?\\?@\lstinline@?\?@} and ©?\=?©\index{?\\=?@\lstinline@?\=?@}, 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) ;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; 516 516 256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i 517 517 \end{cfa} 518 Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©.518 Parenthesis are necessary for the 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@/\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.} 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.} 546 539 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 \hline566 \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 empty620 empty621 empty622 zero623 A624 A A A A A A A A A A625 B B B B B626 C C C C C627 D D D D D628 E E E E E629 0 1 2 3 4 5 6 7 8 9630 1 3 5 7 9631 10 8 6 4 2632 0.5 1.5 2.5 3.5 4.5633 5.5 4.5 3.5 2.5 1.5634 2 4 6 8 10635 10 8 6 4 2636 637 N N N N N N N N N N638 0 1 2 3 4 5 6 7 8 9639 10 9 8 7 6 5 4 3 2 1640 641 3 6 9642 \end{cfa}643 \end{tabular}644 \end{cquote}645 540 646 541 … … 905 800 906 801 907 % for () => for ( ;; )908 % for ( 10 - t ) => for ( typeof(10 - t) ? = 0 ; ? < 10 - t; ? += 1 ) // using 0 and 1909 % for ( i ; 10 - t ) => for ( typeof(10 - t) i = 0 ; i < 10 - t; i += 1 ) // using 0 and 1910 % for ( T i ; 10 - t ) => for ( T i = 0 ; i < 10 - t; i += 1 ) // using 0 and 1911 % for ( 3~9 ) => for ( int ? = 3 ; ? < 9; ? += 1 ) // using 1912 % for ( i ; 3~9 ) => for ( int i = 3 ; i < 9; i += 1 ) // using 1913 % for ( T i ; 3~9 ) => for ( T i = 3 ; i < 9; i += 1 ) // using 1914 915 916 802 %\subsection{\texorpdfstring{Labelled \protect\lstinline@continue@ / \protect\lstinline@break@}{Labelled continue / break}} 917 803 \subsection{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break} Statement}{Labelled continue / break Statement}} … … 919 805 While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure. 920 806 Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting. 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.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. 922 808 For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement; 923 809 for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement. … … 1004 890 \end{figure} 1005 891 1006 Both labelled ©continue© and ©break© are a ©goto©\index{goto@ ©goto©!restricted} restricted in the following ways:892 Both labelled ©continue© and ©break© are a ©goto©\index{goto@\lstinline@goto@!restricted} restricted in the following ways: 1007 893 \begin{itemize} 1008 894 \item … … 1561 1447 \end{cfa} 1562 1448 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. 1563 Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices. 1449 Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices. 1564 1450 1565 1451 Rather than inferring dereference, most programming languages pick one implicit dereferencing semantics, and the programmer explicitly indicates the other to resolve address-duality. … … 2396 2282 struct T t; 2397 2283 } s; 2398 2284 2399 2285 2400 2286 … … 2459 2345 int bar( int p ) { 2460 2346 ®i® += 1; §\C{// dependent on local variable}§ 2461 sout | ®i® ;2347 sout | ®i® | endl; 2462 2348 } 2463 2349 return bar; §\C{// undefined because of local dependence}§ … … 2465 2351 int main() { 2466 2352 * [int]( int ) fp = foo(); §\C{// int (* fp)( int )}§ 2467 sout | fp( 3 ) ;2468 } 2469 \end{cfa} 2470 because 2353 sout | fp( 3 ) | endl; 2354 } 2355 \end{cfa} 2356 because 2471 2357 2472 2358 Currently, there are no \Index{lambda} expressions, \ie unnamed routines because routine names are very important to properly select the correct routine. … … 3231 3117 \begin{cfa} 3232 3118 int x = 1, y = 2, z = 3; 3233 sout | x ®|® y ®|® z ;3119 sout | x ®|® y ®|® z | endl; 3234 3120 \end{cfa} 3235 3121 & … … 3252 3138 \begin{cfa} 3253 3139 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ]; 3254 sout | t1 | t2 ;§\C{// print tuples}§3140 sout | t1 | t2 | endl; §\C{// print tuples}§ 3255 3141 \end{cfa} 3256 3142 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3264 3150 & 3265 3151 \begin{cfa} 3266 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) ;3152 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl; 3267 3153 \end{cfa} 3268 3154 \\ … … 3290 3176 A separator does not appear at the start or end of a line. 3291 3177 \begin{cfa}[belowskip=0pt] 3292 sout | 1 | 2 | 3 ;3178 sout | 1 | 2 | 3 | endl; 3293 3179 \end{cfa} 3294 3180 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3299 3185 A separator does not appear before or after a character literal or variable. 3300 3186 \begin{cfa} 3301 sout | '1' | '2' | '3' ;3187 sout | '1' | '2' | '3' | endl; 3302 3188 123 3303 3189 \end{cfa} … … 3306 3192 A separator does not appear before or after a null (empty) C string. 3307 3193 \begin{cfa} 3308 sout | 1 | "" | 2 | "" | 3 ;3194 sout | 1 | "" | 2 | "" | 3 | endl; 3309 3195 123 3310 3196 \end{cfa} … … 3316 3202 \begin{cfa}[mathescape=off] 3317 3203 sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥" 3318 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 ;3204 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl; 3319 3205 \end{cfa} 3320 3206 %$ … … 3330 3216 \begin{cfa}[belowskip=0pt] 3331 3217 sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x" 3332 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" ;3218 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl; 3333 3219 \end{cfa} 3334 3220 \begin{cfa}[basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3340 3226 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@ 3341 3227 \begin{cfa}[belowskip=0pt] 3342 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" ;3228 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl; 3343 3229 \end{cfa} 3344 3230 \begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt] … … 3349 3235 If a space is desired before or after one of the special string start/end characters, simply insert a space. 3350 3236 \begin{cfa}[belowskip=0pt] 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 ;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; 3352 3238 \end{cfa} 3353 3239 \begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt] … … 3366 3252 \begin{cfa}[mathescape=off,belowskip=0pt] 3367 3253 sepSet( sout, ", $" ); §\C{// set separator from " " to ", \$"}§ 3368 sout | 1 | 2 | 3 | " \"" | ®sep® | "\"" ;3254 sout | 1 | 2 | 3 | " \"" | ®sep® | "\"" | endl; 3369 3255 \end{cfa} 3370 3256 %$ … … 3375 3261 \begin{cfa}[belowskip=0pt] 3376 3262 sepSet( sout, " " ); §\C{// reset separator to " "}§ 3377 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" ;3263 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl; 3378 3264 \end{cfa} 3379 3265 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3385 3271 strcpy( store, sepGet( sout ) ); §\C{// copy current separator}§ 3386 3272 sepSet( sout, "_" ); §\C{// change separator to underscore}§ 3387 sout | 1 | 2 | 3 ;3273 sout | 1 | 2 | 3 | endl; 3388 3274 \end{cfa} 3389 3275 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3392 3278 \begin{cfa}[belowskip=0pt] 3393 3279 sepSet( sout, store ); §\C{// change separator back to original}§ 3394 sout | 1 | 2 | 3 ;3280 sout | 1 | 2 | 3 | endl; 3395 3281 \end{cfa} 3396 3282 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3403 3289 \begin{cfa}[belowskip=0pt] 3404 3290 sepSetTuple( sout, " " ); §\C{// set tuple separator from ", " to " "}§ 3405 sout | t1 | t2 | " \"" | ®sepTuple® | "\"" ;3291 sout | t1 | t2 | " \"" | ®sepTuple® | "\"" | endl; 3406 3292 \end{cfa} 3407 3293 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3410 3296 \begin{cfa}[belowskip=0pt] 3411 3297 sepSetTuple( sout, ", " ); §\C{// reset tuple separator to ", "}§ 3412 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" ;3298 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl; 3413 3299 \end{cfa} 3414 3300 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 3420 3306 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. 3421 3307 \begin{cfa}[belowskip=0pt] 3422 sout | sepDisable | 1 | 2 | 3 ;§\C{// globally turn off implicit separator}§3308 sout | sepDisable | 1 | 2 | 3 | endl; §\C{// globally turn off implicit separator}§ 3423 3309 \end{cfa} 3424 3310 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3426 3312 \end{cfa} 3427 3313 \begin{cfa}[belowskip=0pt] 3428 sout | sepEnable | 1 | 2 | 3 ; §\C{// globally turn on implicit separator}§3314 sout | sepEnable | 1 | 2 | 3 | endl; §\C{// globally turn on implicit separator}§ 3429 3315 \end{cfa} 3430 3316 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3435 3321 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. 3436 3322 \begin{cfa}[belowskip=0pt] 3437 sout | 1 | sepOff | 2 | 3 ; §\C{// locally turn off implicit separator}§3323 sout | 1 | sepOff | 2 | 3 | endl; §\C{// locally turn off implicit separator}§ 3438 3324 \end{cfa} 3439 3325 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3441 3327 \end{cfa} 3442 3328 \begin{cfa}[belowskip=0pt] 3443 sout | sepDisable | 1 | sepOn | 2 | 3 ; §\C{// locally turn on implicit separator}§3329 sout | sepDisable | 1 | sepOn | 2 | 3 | endl; §\C{// locally turn on implicit separator}§ 3444 3330 \end{cfa} 3445 3331 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3448 3334 The tuple separator also responses to being turned on and off. 3449 3335 \begin{cfa}[belowskip=0pt] 3450 sout | t1 | sepOff | t2 ; §\C{// locally turn on/off implicit separator}§3336 sout | t1 | sepOff | t2 | endl; §\C{// locally turn on/off implicit separator}§ 3451 3337 \end{cfa} 3452 3338 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3456 3342 use ©sep© to accomplish this functionality. 3457 3343 \begin{cfa}[belowskip=0pt] 3458 sout | sepOn | 1 | 2 | 3 | sepOn ; §\C{// sepOn does nothing at start/end of line}§3344 sout | sepOn | 1 | 2 | 3 | sepOn | endl ; §\C{// sepOn does nothing at start/end of line}§ 3459 3345 \end{cfa} 3460 3346 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3462 3348 \end{cfa} 3463 3349 \begin{cfa}[belowskip=0pt] 3464 sout | sep | 1 | 2 | 3 | sep ; §\C{// use sep to print separator at start/end of line}§3350 sout | sep | 1 | 2 | 3 | sep | endl ; §\C{// use sep to print separator at start/end of line}§ 3465 3351 \end{cfa} 3466 3352 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 3475 3361 int main( void ) { 3476 3362 int x = 1, y = 2, z = 3; 3477 sout | x | y | z ;3363 sout | x | y | z | endl; 3478 3364 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ]; 3479 sout | t1 | t2 ; // print tuples3480 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 ;3365 sout | t1 | t2 | endl; // print tuples 3366 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; 3484 3370 sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥" 3485 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 ;3371 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl; 3486 3372 sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x" 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 ;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; 3490 3376 3491 3377 sepSet( sout, ", $" ); // set separator from " " to ", $" 3492 sout | 1 | 2 | 3 | " \"" | sep | "\"" ;3378 sout | 1 | 2 | 3 | " \"" | sep | "\"" | endl; 3493 3379 sepSet( sout, " " ); // reset separator to " " 3494 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" ;3380 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl; 3495 3381 3496 3382 char store[sepSize]; 3497 3383 strcpy( store, sepGet( sout ) ); 3498 3384 sepSet( sout, "_" ); 3499 sout | 1 | 2 | 3 ;3385 sout | 1 | 2 | 3 | endl; 3500 3386 sepSet( sout, store ); 3501 sout | 1 | 2 | 3 ;3387 sout | 1 | 2 | 3 | endl; 3502 3388 3503 3389 sepSetTuple( sout, " " ); // set tuple separator from ", " to " " 3504 sout | t1 | t2 | " \"" | sepTuple | "\"" ;3390 sout | t1 | t2 | " \"" | sepTuple | "\"" | endl; 3505 3391 sepSetTuple( sout, ", " ); // reset tuple separator to ", " 3506 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" ;3507 3508 sout | sepDisable | 1 | 2 | 3 ; // globally turn off implicit separator3509 sout | sepEnable | 1 | 2 | 3 ; // globally turn on implicit separator3510 3511 sout | 1 | sepOff | 2 | 3 ; // locally turn on implicit separator3512 sout | sepDisable | 1 | sepOn | 2 | 3 ; // globally turn off implicit separator3392 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl; 3393 3394 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separator 3395 sout | sepEnable | 1 | 2 | 3 | endl; // globally turn on implicit separator 3396 3397 sout | 1 | sepOff | 2 | 3 | endl; // locally turn on implicit separator 3398 sout | sepDisable | 1 | sepOn | 2 | 3 | endl; // globally turn off implicit separator 3513 3399 sout | sepEnable; 3514 sout | t1 | sepOff | t2 ; // locally turn on/off implicit separator3515 3516 sout | sepOn | 1 | 2 | 3 | sepOn ; // sepOn does nothing at start/end of line3517 sout | sep | 1 | 2 | 3 | sep ; // use sep to print separator at start/end of line3400 sout | t1 | sepOff | t2 | endl; // locally turn on/off implicit separator 3401 3402 sout | sepOn | 1 | 2 | 3 | sepOn | endl ; // sepOn does nothing at start/end of line 3403 sout | sep | 1 | 2 | 3 | sep | endl ; // use sep to print separator at start/end of line 3518 3404 } 3519 3405 … … 4180 4066 Fibonacci f1, f2; 4181 4067 for ( int i = 1; i <= 10; i += 1 ) { 4182 sout | next( &f1 ) | ' ' | next( &f2 ) ;4068 sout | next( &f1 ) | ' ' | next( &f2 ) | endl; 4183 4069 } // for 4184 4070 } … … 4246 4132 MyThread f[4]; 4247 4133 } 4248 sout | global.value ;4134 sout | global.value | endl; 4249 4135 } 4250 4136 \end{cfa} … … 4324 4210 void main( First * this ) { 4325 4211 for ( int i = 0; i < 10; i += 1 ) { 4326 sout | "First : Suspend No." | i + 1 ;4212 sout | "First : Suspend No." | i + 1 | endl; 4327 4213 yield(); 4328 4214 } … … 4333 4219 wait( this->lock ); 4334 4220 for ( int i = 0; i < 10; i += 1 ) { 4335 sout | "Second : Suspend No." | i + 1 ;4221 sout | "Second : Suspend No." | i + 1 | endl; 4336 4222 yield(); 4337 4223 } … … 4340 4226 int main( void ) { 4341 4227 signal_once lock; 4342 sout | "User main begin" ;4228 sout | "User main begin" | endl; 4343 4229 { 4344 4230 processor p; … … 4348 4234 } 4349 4235 } 4350 sout | "User main end" ;4236 sout | "User main end" | endl; 4351 4237 } 4352 4238 \end{cfa} … … 5045 4931 void ?{}( Line * l ) { 5046 4932 l->lnth = 0.0; 5047 sout | "default" ;4933 sout | "default" | endl; 5048 4934 } 5049 4935 … … 5052 4938 void ?{}( Line * l, float lnth ) { 5053 4939 l->lnth = lnth; 5054 sout | "lnth" | l->lnth ;4940 sout | "lnth" | l->lnth | endl; 5055 4941 5056 4942 } … … 5058 4944 // destructor 5059 4945 void ^?() { 5060 sout | "destroyed" ;4946 sout | "destroyed" | endl; 5061 4947 l.lnth = 0.0; 5062 4948 } … … 5804 5690 In particular, output of ©char© variable now print a character rather than the decimal ASCII value of the character. 5805 5691 \begin{cfa} 5806 sout | 'x' | " " | (int)'x' ;5692 sout | 'x' | " " | (int)'x' | endl; 5807 5693 x 120 5808 5694 \end{cfa} … … 7034 6920 #include <gmp>§\indexc{gmp}§ 7035 6921 int main( void ) { 7036 sout | "Factorial Numbers" ;6922 sout | "Factorial Numbers" | endl; 7037 6923 Int fact = 1; 7038 6924 7039 sout | 0 | fact ;6925 sout | 0 | fact | endl; 7040 6926 for ( unsigned int i = 1; i <= 40; i += 1 ) { 7041 6927 fact *= i; 7042 sout | i | fact ;6928 sout | i | fact | endl; 7043 6929 } 7044 6930 }
Note:
See TracChangeset
for help on using the changeset viewer.