Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    rba80f99 rd92ff4a  
    11%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
    2 %%
     2%% 
    33%% Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
    44%%
    55%% The contents of this file are covered under the licence agreement in the
    66%% file "LICENCE" distributed with Cforall.
    7 %%
    8 %% user.tex --
    9 %%
     7%% 
     8%% user.tex -- 
     9%% 
    1010%% Author           : Peter A. Buhr
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Fri Aug 31 07:54:50 2018
    14 %% Update Count     : 3396
     13%% Last Modified On : Thu Jul 26 17:29:05 2018
     14%% Update Count     : 3366
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    7272
    7373% Names used in the document.
    74 \newcommand{\Version}{\input{build/version}}
     74\newcommand{\Version}{\input{../../version}}
    7575\newcommand{\Textbf}[2][red]{{\color{#1}{\textbf{#2}}}}
    7676\newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}}
     
    210210Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction.
    211211For 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.
     212The 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.
    213213The top 3 rankings over the past 30 years are:
    214214\begin{center}
     
    351351The 2011 C standard plus GNU extensions.
    352352\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@}}
    354354Use the traditional GNU semantics for inline routines in C11 mode, which allows inline routines in header files.
    355355\end{description}
     
    430430#endif
    431431\end{cfa}
    432 which conditionally includes the correct header file, if the program is compiled using \Indexc{gcc} or \Indexc{cfa}.
     432which conditionally includes the correct header file, if the program is compiled using \Indexc{gcc} or \Indexc{cfa}. 
    433433
    434434
     
    455455#endif
    456456
    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}§
    458458®
    459459#if defined( with ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§
     
    504504
    505505C, \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$.
    507507The 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)©.
    508508
     
    516516256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i
    517517\end{cfa}
    518 Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©.
     518Parenthesis are necessary for the complex constants or the expression is parsed as ©1.0f+(2.0fi \ 3.0f)+2.0fi©.
    519519The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation versions are available.
    520520For returning an integral value, the user type ©T© must define multiplication, ©*©, and one, ©1©;
     
    527527
    528528
    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
     532The ©if© expression allows declarations, similar to ©for© declaration expression:
     533\begin{cfa}
     534if ( int x = f() ) ...                                          §\C{// x != 0}§
     535if ( int x = f(), y = g() ) ...                         §\C{// x != 0 \&\& y != 0}§
     536if ( int x = f(), y = g(); ®x < y® ) ...        §\C{// relational expression}§
     537\end{cfa}
     538Unless 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.}
    546539The scope of the declaration(s) is local to the @if@ statement but exist within both the ``then'' and ``else'' clauses.
    547 
    548 
    549 %\subsection{\texorpdfstring{\protect\lstinline@for@ Statement}{for Statement}}
    550 \subsection{\texorpdfstring{\LstKeywordStyle{for} Statement}{for Statement}}
    551 
    552 The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges.
    553 An empty conditional implies ©1©.
    554 The up-to range ©~©\index{~@©~©} means exclusive range [M,N);
    555 the up-to range ©~=©\index{~=@©~=©} means inclusive range [M,N].
    556 The down-to range ©-~©\index{-~@©-~©} means exclusive range [N,M);
    557 the down-to range ©-~=©\index{-~=@©-~=©} means inclusive range [N,M].
    558 ©0© is the implicit start value;
    559 ©1© is the implicit increment value for an up-to range and ©-1© for an implicit down-to range.
    560 The loop index is polymorphic in the type of the start value or comparison value when start is implicitly ©0©.
    561 \begin{cquote}
    562 \begin{tabular}{@{}ll|l@{}}
    563 \multicolumn{2}{c|}{for control} & \multicolumn{1}{c}{output} \\
    564 \hline
    565 \begin{cfa}
    566 while ®()® { sout | "empty"; break; }
    567 do { sout | "empty"; break; } while ®()®;
    568 for ®()® { sout | "empty"; break; }
    569 for ( ®0® ) { sout | "A"; }
    570 for ( ®1® ) { sout | "A"; }
    571 for ( ®10® ) { sout | "A"; }
    572 for ( ®1 ~= 10 ~ 2® ) { sout | "B"; }
    573 for ( ®10 -~= 1 ~ -2® ) { sout | "C"; }
    574 for ( ®0.5 ~ 5.5® ) { sout | "D"; }
    575 for ( ®5.5 -~ 0.5® ) { sout | "E"; }
    576 for ( ®i; 10® ) { sout | i; }
    577 for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; }
    578 for ( ®i; 10 -~= 1 ~ -2® ) { sout | i; }
    579 for ( ®i; 0.5 ~ 5.5® ) { sout | i; }
    580 for ( ®i; 5.5 -~ 0.5® ) { sout | i; }
    581 for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; }
    582 for ( ®ui; 10u -~= 2u ~ -2u® ) { sout | ui; }
    583 int start = 3, comp = 10, inc = 2;
    584 for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; }
    585 \end{cfa}
    586 &
    587 \begin{cfa}
    588 sout | endl;
    589 sout | endl;
    590 sout | endl;
    591 sout | endl;
    592 sout | endl;
    593 sout | endl;
    594 sout | endl;
    595 sout | endl;
    596 sout | endl;
    597 sout | endl;
    598 sout | endl;
    599 sout | endl;
    600 sout | endl;
    601 sout | endl;
    602 sout | endl;
    603 sout | endl;
    604 sout | endl;
    605 
    606 sout | endl;
    607 \end{cfa}
    608 &
    609 \begin{cfa}
    610 empty
    611 empty
    612 empty
    613 
    614 A
    615 A A A A A A A A A A
    616 B B B B B
    617 C C C C C
    618 D D D D D
    619 E E E E E
    620 0 1 2 3 4 5 6 7 8 9
    621 1 3 5 7 9
    622 10 8 6 4 2
    623 0.5 1.5 2.5 3.5 4.5
    624 5.5 4.5 3.5 2.5 1.5
    625 2 4 6 8 10
    626 10 8 6 4 2
    627 
    628 3 6 9
    629 \end{cfa}
    630 \end{tabular}
    631 \end{cquote}
    632540
    633541
     
    892800
    893801
    894 % for ()  => for ( ;; )
    895 % for ( 10 - t ) => for ( typeof(10 - t) ? = 0 ; ? < 10 - t; ? += 1 ) // using 0 and 1
    896 % for ( i ; 10 - t ) => for ( typeof(10 - t) i = 0 ; i < 10 - t; i += 1 ) // using 0 and 1
    897 % for ( T i ; 10 - t ) => for ( T i = 0 ; i < 10 - t; i += 1 ) // using 0 and 1
    898 % for ( 3~9 ) => for ( int ? = 3 ; ? < 9; ? += 1 ) // using 1
    899 % for ( i ; 3~9 ) => for ( int i = 3 ; i < 9; i += 1 ) // using 1
    900 % for ( T i ; 3~9 ) => for ( T i = 3 ; i < 9; i += 1 ) // using 1
    901 
    902 
    903802%\subsection{\texorpdfstring{Labelled \protect\lstinline@continue@ / \protect\lstinline@break@}{Labelled continue / break}}
    904803\subsection{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break} Statement}{Labelled continue / break Statement}}
     
    906805While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure.
    907806Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting.
    908 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.
     807To 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.
    909808For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement;
    910809for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement.
     
    991890\end{figure}
    992891
    993 Both labelled ©continue© and ©break© are a ©goto©\index{goto@©goto©!restricted} restricted in the following ways:
     892Both labelled ©continue© and ©break© are a ©goto©\index{goto@\lstinline@goto@!restricted} restricted in the following ways:
    994893\begin{itemize}
    995894\item
     
    15481447\end{cfa}
    15491448Algol68 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.
    1550 Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices.
     1449Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices. 
    15511450
    15521451Rather than inferring dereference, most programming languages pick one implicit dereferencing semantics, and the programmer explicitly indicates the other to resolve address-duality.
     
    23832282        struct T t;
    23842283} s;
    2385 
     2284       
    23862285
    23872286
     
    24552354}
    24562355\end{cfa}
    2457 because
     2356because 
    24582357
    24592358Currently, there are no \Index{lambda} expressions, \ie unnamed routines because routine names are very important to properly select the correct routine.
     
    34953394        sout | sepDisable | 1 | 2 | 3 | endl;           // globally turn off implicit separator
    34963395        sout | sepEnable | 1 | 2 | 3 | endl;            // globally turn on implicit separator
    3497 
     3396       
    34983397        sout | 1 | sepOff | 2 | 3 | endl;                       // locally turn on implicit separator
    34993398        sout | sepDisable | 1 | sepOn | 2 | 3 | endl; // globally turn off implicit separator
Note: See TracChangeset for help on using the changeset viewer.