Changes in doc/user/user.tex [e945826:6c91065]
- File:
-
- 1 edited
-
doc/user/user.tex (modified) (63 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
re945826 r6c91065 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%2 %%3 %% Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo4 %%5 %% The contents of this file are covered under the licence agreement in the6 %% file "LICENCE" distributed with Cforall.7 %%8 %% user.tex --9 %%10 %% Author : Peter A. Buhr11 %% Created On : Wed Apr 6 14:53:29 201612 %% Last Modified By : Peter A. Buhr13 %% Last Modified On : Sat Apr 30 13:54:32 201614 %% Update Count : 22115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%16 17 1 % requires tex packages: texlive-base texlive-latex-base tex-common texlive-humanities texlive-latex-extra texlive-fonts-recommended 18 19 % red highlighting ®...® (registered trademark sumbol)20 % blue highlighting ©...© (copyright symbol)21 % latex escape §...§ (section symbol)22 % keyword escape ¶...¶ (pilcrow symbol)23 % math escape $...$ (dollar symbol)24 2 25 3 \documentclass[openright,twoside]{article} … … 27 5 28 6 % Latex packages used in the document. 29 \usepackage[T1]{fontenc} % allow Latin1 (extended ASCII) characters 30 \usepackage{textcomp} 31 \usepackage[latin1]{inputenc} 32 \usepackage{upquote} 7 33 8 \usepackage{fullpage,times} 34 \usepackage{epic,eepic}35 9 \usepackage{xspace} 36 10 \usepackage{varioref} … … 38 12 \usepackage{footmisc} 39 13 \usepackage{comment} 40 \usepackage{latexsym} % \Box41 \usepackage{mathptmx} % better math font with "times"14 \usepackage{latexsym} % \Box 15 \usepackage{mathptmx} % better math font with "times" 42 16 \usepackage[pagewise]{lineno} 43 17 \renewcommand{\linenumberfont}{\scriptsize\sffamily} … … 48 22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 49 23 24 % Names used in the document. 25 26 \newcommand{\CFA}{C$\forall$\xspace} % set language symbolic name 27 \newcommand{\CFL}{Cforall\xspace} % set language text name 28 \newcommand{\CC}{C\kern-.1em\hbox{+\kern-.25em+}\xspace} % CC symbolic name 29 \def\c11{ISO/IEC C} % C11 name (cannot have numbers in latex command name) 30 \newcommand{\CS}{C\raisebox{-0.9ex}{\large$^\sharp$}\xspace} 31 32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 33 50 34 % Bespoke macros used in the document. 51 \input{common} 52 53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 54 55 % Names used in the document. 56 57 \newcommand{\Version}{1.0.0} 58 \newcommand{\CS}{C\raisebox{-0.9ex}{\large$^\sharp$}\xspace} 59 60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 61 62 \setcounter{secnumdepth}{3} % number subsubsections 63 \setcounter{tocdepth}{3} % subsubsections in table of contents 35 36 \makeatletter 37 % allow escape sequence in lstinline 38 %\usepackage{etoolbox} 39 %\patchcmd{\lsthk@TextStyle}{\let\lst@DefEsc\@empty}{}{}{\errmessage{failed to patch}} 40 41 \renewcommand\small{% 42 \@setfontsize\small{8.5}{11}% 43 \abovedisplayskip 8.5pt \@plus 3pt \@minus 4pt 44 \abovedisplayshortskip \z@ \@plus 2pt 45 \belowdisplayshortskip 4pt \@plus 2pt \@minus 2pt 46 \def\@listi{\leftmargin\leftmargini 47 \topsep 4pt \@plus 2pt \@minus 2pt 48 \parsep 2pt \@pluspt \@minuspt 49 \itemsep \parsep}% 50 \belowdisplayskip \abovedisplayskip 51 } 52 \usepackage{relsize} % must be after change to small 53 54 \renewcommand{\labelitemi}{{\raisebox{0.25ex}{\footnotesize$\bullet$}}} 55 \renewenvironment{itemize}{\begin{list}{\labelitemi}{\topsep=5pt\itemsep=5pt\parsep=0pt}}{\end{list}} 56 57 % Reduce size of section titles 58 \renewcommand\section{\@startsection{section}{1}{\z@}{-3.0ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\large\bfseries}} 59 \renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}} 60 \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}} 61 \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}} 62 63 % index macros 64 \newcommand{\italic}[1]{\emph{\hyperpage{#1}}} 65 \newcommand{\definition}[1]{\textbf{\hyperpage{#1}}} 66 \newcommand{\see}[1]{\emph{see} #1} 67 68 % Define some commands that produce formatted index entries suitable for cross-references. 69 % ``\spec'' produces entries for specifications of entities. ``\impl'' produces entries for their 70 % implementations, and ``\use'' for their uses. 71 72 % \newcommand{\bold}[1]{{\bf #1}} 73 % \def\spec{\@bsphack\begingroup 74 % \def\protect##1{\string##1\space}\@sanitize 75 % \@wrxref{|bold}} 76 \def\impl{\@bsphack\begingroup 77 \def\protect##1{\string##1\space}\@sanitize 78 \@wrxref{|definition}} 79 \newcommand{\indexcode}[1]{{\lstinline$#1$}} 80 \def\use{\@bsphack\begingroup 81 \def\protect##1{\string##1\space}\@sanitize 82 \@wrxref{|hyperpage}} 83 \def\@wrxref#1#2{\let\thepage\relax 84 \xdef\@gtempa{\write\@indexfile{\string 85 \indexentry{#2@{\lstinline$#2$}#1}{\thepage}}}\endgroup\@gtempa 86 \if@nobreak \ifvmode\nobreak\fi\fi\@esphack} 87 %\newcommand{\use}[1]{\index{#1@{\lstinline$#1$}}} 88 %\newcommand{\impl}[1]{\index{\protect#1@{\lstinline$\protect#1$}|definition}} 89 90 % inline text and lowercase index: \Index{inline and lowercase index text} 91 % inline text and as-in index: \Index[as-is index text]{inline text} 92 % inline text but index with different as-is text: \Index[index text]{inline text} 93 \newcommand{\Index}{\@ifstar\@sIndex\@Index} 94 \newcommand{\@Index}[2][\@empty]{\lowercase{\def\temp{#2}}#2\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi} 95 \newcommand{\@sIndex}[2][\@empty]{#2\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi} 96 97 \newcommand{\newtermFontInline}{\emph} 98 \newcommand{\newterm}{\@ifstar\@snewterm\@newterm} 99 \newcommand{\@newterm}[2][\@empty]{\lowercase{\def\temp{#2}}{\newtermFontInline{#2}}\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi} 100 \newcommand{\@snewterm}[2][\@empty]{{\newtermFontInline{#2}}\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi} 101 \makeatother 102 103 % blocks and titles 104 \newenvironment{quote2}{% 105 \list{}{\lstset{resetmargins=true}\leftmargin=\parindent\rightmargin\leftmargin}% 106 \item\relax 107 }{% 108 \endlist 109 }% quote2 110 \newenvironment{rationale}{% 111 \begin{quotation}\noindent$\Box$\enspace 112 }{% 113 \hfill\enspace$\Box$\end{quotation} 114 }% 115 \newcommand{\define}[1]{\emph{#1\/}\index{#1}} 116 \newcommand{\rewrite}{\(\Rightarrow\)} 117 \newcommand{\rewriterules}{\paragraph{Rewrite Rules}~\par\noindent} 118 \newcommand{\examples}{\paragraph{Examples}~\par\noindent} 119 \newcommand{\semantics}{\paragraph{Semantics}~\par\noindent} 120 \newcommand{\constraints}{\paragraph{Constraints}~\par\noindent} 121 \newcommand{\predefined}{\paragraph{Predefined Identifiers}~\par\noindent} 122 123 % BNF macros 124 \def\syntax{\paragraph{Syntax}\trivlist\parindent=.5in\item[\hskip.5in]} 125 \let\endsyntax=\endtrivlist 126 \newcommand{\lhs}[1]{\par{\emph{#1:}}\index{#1@{\emph{#1}}|italic}} 127 \newcommand{\rhs}{\hfil\break\hbox{\hskip1in}} 128 \newcommand{\oldlhs}[1]{\emph{#1: \ldots}\index{#1@{\emph{#1}}|italic}} 129 \newcommand{\nonterm}[1]{\emph{#1\/}\index{#1@{\emph{#1}}|italic}} 130 \newcommand{\opt}{$_{opt}$\ } 131 132 % adjust varioref package with default "section" and "page" titles, and optional title with faraway page numbers 133 % \VRef{label} => Section 2.7, \VPageref{label} => page 17 134 % \VRef[Figure]{label} => Figure 3.4, \VPageref{label} => page 17 135 \renewcommand{\reftextfaceafter}{\unskip} 136 \renewcommand{\reftextfacebefore}{\unskip} 137 \renewcommand{\reftextafter}{\unskip} 138 \renewcommand{\reftextbefore}{\unskip} 139 \renewcommand{\reftextfaraway}[1]{\unskip, p.~\pageref{#1}} 140 \renewcommand{\reftextpagerange}[2]{\unskip, pp.~\pageref{#1}--\pageref{#2}} 141 \newcommand{\VRef}[2][Section]{\ifx#1\@empty\else{#1}\nobreakspace\fi\vref{#2}} 142 \newcommand{\VPageref}[2][page]{\ifx#1\@empty\else{#1}\nobreakspace\fi\pageref{#2}} 143 144 % Go programming language 145 \lstdefinelanguage{Golang}% 146 {morekeywords=[1]{package,import,func,type,struct,return,defer,panic, recover,select,var,const,iota,},% 147 morekeywords=[2]{string,uint,uint8,uint16,uint32,uint64,int,int8,int16, int32,int64, 148 bool,float32,float64,complex64,complex128,byte,rune,uintptr, error,interface},% 149 morekeywords=[3]{map,slice,make,new,nil,len,cap,copy,close,true,false, delete,append,real,imag,complex,chan,},% 150 morekeywords=[4]{for,break,continue,range,goto,switch,case,fallthrough,if, else,default,},% 151 morekeywords=[5]{Println,Printf,Error,},% 152 sensitive=true,% 153 morecomment=[l]{//},% 154 morecomment=[s]{/*}{*/},% 155 morestring=[b]',% 156 morestring=[b]",% 157 morestring=[s]{`}{`},% 158 } 159 160 % CFA based on ANSI C 161 \lstdefinelanguage{CFA}[ANSI]{C}% 162 {morekeywords={asm,_Alignas,_Alignof,_At,_Atomic,_Bool,catch,catchResume,choose,_Complex,trait,disable,dtype,enable, 163 fallthru,finally,forall,ftype,_Generic,_Imaginary,inline,lvalue,_Noreturn,otype,restrict,_Static_assert, 164 _Thread_local,throw,throwResume,try,}, 165 }% 166 167 \lstset{ 168 language=CFA, 169 columns=flexible, 170 basicstyle=\sf\relsize{-1}, 171 tabsize=4, 172 xleftmargin=\parindent, 173 escapechar=@, 174 mathescape=true, 175 keepspaces=true, 176 showstringspaces=false, 177 showlines=true, 178 }% 179 180 \makeatletter 181 % replace/adjust listings characters that look bad in sanserif 182 \lst@CCPutMacro 183 \lst@ProcessOther{"2D}{\lst@ttfamily{-{}}{{\ttfamily\upshape -}}} % replace minus 184 \lst@ProcessOther{"3C}{\lst@ttfamily{<}{\texttt{<}}} % replace less than 185 \lst@ProcessOther{"3E}{\lst@ttfamily{<}{\texttt{>}}} % replace greater than 186 \lst@ProcessOther{"5E}{\raisebox{0.4ex}{$\scriptstyle\land\,$}} % replace circumflex 187 \lst@ProcessLetter{"5F}{\lst@ttfamily{\char95}{{\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}}} % replace underscore 188 \lst@ProcessOther{"7E}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}} % replace tilde 189 %\lst@ProcessOther{"7E}{\raisebox{-.4ex}[1ex][0pt]{\textasciitilde}} % lower tilde 190 \@empty\z@\@empty 191 \makeatother 192 193 \setcounter{secnumdepth}{3} % number subsubsections 194 \setcounter{tocdepth}{3} % subsubsections in table of contents 64 195 \makeindex 65 196 … … 68 199 \begin{document} 69 200 \pagestyle{headings} 70 \linenumbers % comment out to turn off line numbering201 \linenumbers % comment out to turn off line numbering 71 202 72 203 \title{\Huge … … 82 213 }% author 83 214 \date{ 84 DRAFT \\ 85 \today 215 DRAFT\\\today 86 216 }% date 87 217 … … 111 241 112 242 \CFA\footnote{Pronounced ``C-for-all'', and written \CFA, CFA, or \CFL.} is a modern general-purpose programming-language, designed an as evolutionary step forward from the C programming language. 113 The syntax of the \CFA language builds from C, and should look immediately familiar to C programmers.243 The syntax of the \CFA language builds from that of C, and should look immediately familiar to C programmers. 114 244 % Any language feature that is not described here can be assumed to be using the standard C11 syntax. 115 \CFA adds many modern programming-language features, which directly leads to increased safety and productivity, while maintaining interoperability with existing C programs and achieving Cperformance.245 \CFA has added many modern programming-language features, which directly leads to increased safety and productivity, while maintaining interoperability with existing C programs, and maintaining C-like performance. 116 246 Like C, \CFA is a statically typed, procedural language with a low-overhead runtime, meaning there is no global garbage-collection. 117 247 The primary new features include parametric-polymorphism routines and types, exceptions, concurrency, and modules. … … 124 254 New programs can be written in \CFA using a combination of C and \CFA features. 125 255 \CC had a similar goal 30 years ago, but has struggled over the intervening time to incorporate modern programming-language features because of early design choices. 126 \CFA has 30 years of hindsight and clean starting point.256 \CFA has 30 years of hindsight and a much cleaner starting point than \CC. 127 257 128 258 Like \CC, there may be both an old and new ways to achieve the same effect. … … 149 279 \end{quote2} 150 280 Both programs output the same result. 151 While the \CFA I/O looks similar to the \CC output style, there are several important differences, such as automatic spacing between variables as in Python (see also~\VRef{s:IOLibrary}).281 While the \CFA I/O looks similar to the \CC style of output, there are several important differences, such as automatic spacing between variables as in Python (see also~\VRef{s:IOLibrary}). 152 282 153 283 This document is a reference manual for the \CFA programming language, targeted at \CFA programmers. 154 Implementers may refer to the \CFA Programming Language Specification for details about the language syntax and semantics.284 Implementers may also refer to the \CFA Programming Language Specification for details about the language syntax and semantics. 155 285 In its current state, this document covers the intended core features of the language. 156 286 Changes to the syntax and additional features are expected to be included in later revisions. … … 164 294 The original \CFA project~\cite{Ditchfield92} extended the C type system with parametric polymorphism and overloading, as opposed to the \CC approach of object-oriented extensions to the C type-system. 165 295 A first implementation of the core Cforall language was created~\cite{Bilson03,Esteves04}, but at the time there was little interesting in extending C, so work did not continue. 166 As the saying goes, ``What goes around, comes around'', and there is now renewed interest in the C programming language because of legacy code-bases, so the \CFA project has been restarted.167 168 169 \section{ Why fix C?}296 As the saying goes, ``What goes around, comes around'', and there is now renewed interest in the C programming language, so the \CFA project has been restarted. 297 298 299 \section{Motivation: Why fix C?} 170 300 171 301 Even with all its problems, C is a very popular programming language because it allows writing software at virtually any level in a computer system without restriction. … … 184 314 Java~\cite{Java8}, Go~\cite{Go}, Rust~\cite{Rust} and D~\cite{D} are examples of the revolutionary approach for modernizing C/\CC, resulting in a new language rather than an extension of the descendent. 185 315 These languages have different syntax and semantics from C, and do not interoperate directly with C, largely because of garbage collection. 186 As a result, there is a significant learning curve to move to these languages, and C legacy-code must be rewritten.316 As a result, there is a significant learning curve to move to these languages, and C legacy-code must be complete rewritten. 187 317 These costs can be prohibitive for many companies with a large software base in C/\CC, and many programmers that require retraining to a new programming language. 188 318 … … 201 331 This feature allows users of \CFA to take advantage of the existing panoply of C libraries from inside their \CFA code. 202 332 In fact, one of the biggest issues for any new programming language is establishing a minimum level of library code to support a large body of activities. 203 Programming-language developers often state that adequate library support takes more workthan designing and implementing the language itself.333 Programming-language developers often state that adequate library support costs many times more than designing and implementing the language itself. 204 334 Like \CC, \CFA starts with immediate access to all exiting C libraries, and in many cases, can easily wrap library routines with simpler and safer interfaces, at very low cost. 205 335 … … 208 338 Whereas, \CFA wraps each of these routines into one with the common name \lstinline@abs@. 209 339 \begin{lstlisting} 340 extern "C" { 341 #include <stdlib.h> // provide C prototype for integer "abs" routine 342 } // extern "C" 343 210 344 char abs( char ); 211 extern "C" { 212 int abs( int ); // use default C routine for int 213 } // extern "C" 214 long int abs( long int ); 345 long int abs( long int ); // @{\CFA}@ overload name "abs" for other types 215 346 long long int abs( long long int ); 216 347 float abs( float ); … … 229 360 The name ``\lstinline@abs@'' evokes the notion of absolute value, and many mathematical types provide the notion of absolute value. 230 361 Hence, knowing the name \lstinline@abs@ should be sufficient to apply it to any type where it is applicable. 231 The time savings and safety of using one name uniformly versus $N$unique names should not be underestimated.232 233 234 \section [Compiling CFA Program]{Compiling \CFA Program}362 The time savings and safety of using one name uniformly versus @N@ unique names should not be underestimated. 363 364 365 \section{Compiling \CFA} 235 366 236 367 The command \lstinline@cfa@ is used to compile \CFA program(s). 237 This command works like the GNU \lstinline@gcc@\index{gcc} command, e.g.: 238 \begin{lstlisting} 239 cfa [ gcc-options ] C/§\CFA§-files [ assembler/loader-files ] 240 \end{lstlisting} 241 \indexc{cfa}\index{compilation!cfa@\lstinline$cfa$} 242 By default, \CFA programs having the following \lstinline@gcc@ flags turned on: 368 This command works like the GNU \lstinline@gcc@ command, e.g.: 369 \begin{lstlisting} 370 cfa [ gcc-options ] C/@{\CFA}@-files [ assembler/loader-files ] 371 \end{lstlisting} 372 The following additional option is available: 243 373 \begin{description} 244 \item\hspace*{-4pt}\Indexc{-std=gnu99}\index{compilation option!-std=gnu99@{\lstinline$-std=gnu99$}} 245 The 1999 C standard plus GNU extensions. 246 \item\hspace*{-4pt}\Indexc{-fgnu89-¶inline¶}\index{compilation option!-fgnu89-inline@{\lstinline$-fgnu89-¶inline¶$}} 247 Use the traditional GNU semantics for inline routines in C99 mode. 248 \end{description} 249 The following new \CFA option is available: 250 \begin{description} 251 \item\hspace*{-4pt}\Indexc{-CFA}\index{compilation option!-CFA@{\lstinline$-CFA$}} 374 \item 375 \hspace*{-4pt}\lstinline@-CFA@ 252 376 Only the C preprocessor and the \CFA translator steps are performed and the transformed program is written to standard output, which makes it possible to examine the code generated by the \CFA translator. 253 377 \end{description} 254 378 255 The following preprocessor variables are available:256 \begin{description}257 \item\hspace*{-4pt}\Indexc{__CFA__}\index{preprocessor variables!__CFA__@{\lstinline$__CFA__$}}258 is always available during preprocessing and its value is the current major \Index{version number} of \CFA.\footnote{259 The C preprocessor allows only integer values in a preprocessor variable so a value like ``\Version'' is not allowed.260 Hence, the need to have three variables for the major, minor and patch version number.}261 262 \item\hspace*{-4pt}\Indexc{__CFA_MINOR__}\index{preprocessor variables!__CFA_MINOR__@{\lstinline$__CFA_MINOR__$}}263 is always available during preprocessing and its value is the current minor \Index{version number} of \CFA.264 265 \item\hspace*{-4pt}\Indexc{__CFA_PATCH__}\index{preprocessor variables!__CFA_PATCH__@\lstinline$__CFA_PATCH__$}266 is always available during preprocessing and its value is the current patch \Index{version number} of \CFA.267 268 \item\hspace*{-4pt}\Indexc{__CFORALL__}\index{preprocessor variables!__CFORALL__@\lstinline$__CFORALL__$}269 is always available during preprocessing and it has no value.270 \end{description}271 272 These preprocessor variables allow conditional compilation of programs that must work differently in these situations.273 For example, to toggle between C and \CFA extensions, using the following:274 \begin{lstlisting}275 #ifndef __CFORALL__276 #include <stdio.h> // C header file277 #else278 #include <fstream> // §\CFA{}§ header file279 #endif280 \end{lstlisting}281 which conditionally includes the correct header file, if the program is compiled using \lstinline@gcc@ or \lstinline@cfa@.282 283 379 284 380 \section{Underscores in Constants} … … 286 382 Numeric constants are extended to allow \Index{underscore}s within constants\index{constant!underscore}, e.g.: 287 383 \begin{lstlisting} 288 2 ®_®147®_®483®_®648; // decimal constant384 2_147_483_648; // decimal constant 289 385 56_ul; // decimal unsigned long constant 290 386 0_377; // octal constant … … 312 408 the type suffixes \lstinline@U@, \lstinline@L@, etc. may start with an underscore \lstinline@1_U@, \lstinline@1_ll@ or \lstinline@1.0E10_f@. 313 409 \end{enumerate} 314 It is significantly easier to read and enterlong constants when they are broken up into smaller groupings (most cultures use comma or period among digits for the same purpose).410 It is significantly easier to read and type long constants when they are broken up into smaller groupings (most cultures use comma or period among digits for the same purpose). 315 411 This extension is backwards compatible, matches with the use of underscore in variable names, and appears in Ada and Java. 316 412 … … 321 417 C declaration syntax is notoriously confusing and error prone. 322 418 For example, many C programmers are confused by a declaration as simple as: 323 \begin{quote2} 324 \begin{tabular}{@{}ll@{}} 325 \begin{lstlisting}[aboveskip=0pt,belowskip=0pt] 326 int *x[ 5 ] 327 \end{lstlisting} 328 & 329 \raisebox{-0.75\totalheight}{\input{Cdecl}} 330 \end{tabular} 331 \end{quote2} 332 Is this an array of 5 pointers to integers or a pointer to an array of 5 integers? 419 \begin{lstlisting} 420 int *x[ 10 ] 421 \end{lstlisting} 422 Is this a pointer to an array of 10 integers or an array of 10 pointers to integers? 333 423 Another example of confusion results from the fact that a routine name and its parameters are embedded within the return type, mimicking the way the return value is used at the routine's call site. 334 424 For example, a routine returning a pointer to an array of integers is defined and used in the following way: 335 425 \begin{lstlisting} 336 int (*f())[ 5 ] {...}; // definition mimics usage337 ... (*f())[ 3 ] += 1; 426 int (*f())[ 10 ] {...}; 427 ... (*f())[ 3 ] += 1; // definition mimics usage 338 428 \end{lstlisting} 339 429 Essentially, the return type is wrapped around the routine name in successive layers (like an onion). … … 344 434 The only exception is bit field specification, which always appear to the right of the base type. 345 435 C and the new \CFA declarations may appear together in the same program block, but cannot be mixed within a specific declaration. 436 Unsupported are K\&R C declarations where the base type defaults to \lstinline@int@, if no type is specified\footnote{ 437 At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each structure declaration and type name~\cite[\S~6.7.2(2)]{C11}}, 438 e.g.: 439 \begin{lstlisting} 440 x; // int x 441 *y; // int *y 442 f( p1, p2 ); // int f( int p1, int p2 ); 443 f( p1, p2 ) {} // int f( int p1, int p2 ) {} 444 \end{lstlisting} 346 445 347 446 In \CFA declarations, the same tokens are used as in C: the character \lstinline@*@ is used to indicate a pointer, square brackets \lstinline@[@\,\lstinline@]@ are used to represent an array, and parentheses \lstinline@()@ are used to indicate a routine parameter. … … 352 451 \multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 353 452 \begin{lstlisting} 354 ®* int x, y;® 453 * int x, y; 355 454 \end{lstlisting} 356 455 & … … 365 464 \multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}} \\ 366 465 \begin{lstlisting} 367 [ 5] int z;368 [ 5] * char w;369 * [ 5] double v;466 [ 10 ] int z; 467 [ 10 ] * char w; 468 * [ 10 ] double v; 370 469 struct s { 371 int f0:3;470 int f0:3; 372 471 * int f1; 373 [ 5] * int f2;472 [ 10 ] * int f2; 374 473 }; 375 474 \end{lstlisting} 376 475 & 377 476 \begin{lstlisting} 378 int z[ 5];379 char *w[ 5];380 double (*v)[ 5];477 int z[ 10 ]; 478 char *w[ 10 ]; 479 double (*v)[ 10 ]; 381 480 struct s { 382 481 int f0:3; 383 482 int *f1; 384 int *f2[ 5]483 int *f2[ 10 ] 385 484 }; 386 485 \end{lstlisting} 387 486 & 388 487 \begin{lstlisting} 389 // array of 5integers390 // array of 5pointers to char391 // pointer to array of 5doubles488 // array of 10 integers 489 // array of 10 pointers to char 490 // pointer to array of 10 doubles 392 491 393 492 // common bit field syntax … … 398 497 \end{tabular} 399 498 \end{quote2} 499 500 As stated above, the two styles of declaration may appear together in the same block. 501 Therefore, a programmer has the option of either continuing to use traditional C declarations or take advantage of the new style. 502 Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX systems. 503 In general, mixing declaration styles in a routine or even a translation unit is not recommended, as it makes a program more difficult to read. 504 Therefore, it is suggested that an entire translation unit be written in one declaration style or the other. 400 505 401 506 All type qualifiers, i.e., \lstinline@const@ and \lstinline@volatile@, are used in the normal way with the new declarations but appear left to right, e.g.: … … 405 510 \begin{lstlisting} 406 511 const * const int x; 407 const * [ 5] const int y;512 const * [ 10 ] const int y; 408 513 \end{lstlisting} 409 514 & 410 515 \begin{lstlisting} 411 516 int const * const x; 412 const int (* const y)[ 5]517 const int (* const y)[ 10 ] 413 518 \end{lstlisting} 414 519 & 415 520 \begin{lstlisting} 416 521 // const pointer to const integer 417 // const pointer to array of 5const integers522 // const pointer to array of 10 const integers 418 523 \end{lstlisting} 419 524 \end{tabular} … … 425 530 \multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}} \\ 426 531 \begin{lstlisting} 427 extern [ 5] int x;532 extern [ 10 ] int x; 428 533 static * const int y; 429 534 \end{lstlisting} 430 535 & 431 536 \begin{lstlisting} 432 int extern x[ 5];537 int extern x[ 10 ]; 433 538 const int static *y; 434 539 \end{lstlisting} 435 540 & 436 541 \begin{lstlisting} 437 // externally visible array of 5integers542 // externally visible array of 10 integers 438 543 // internally visible pointer to constant int 439 544 \end{lstlisting} 440 545 \end{tabular} 441 546 \end{quote2} 442 443 Unsupported are K\&R C declarations where the base type defaults to \lstinline@int@, if no type is specified\footnote{444 At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each structure declaration and type name~\cite[\S~6.7.2(2)]{C11}},445 e.g.:446 \begin{lstlisting}447 x; // int x448 *y; // int *y449 f( p1, p2 ); // int f( int p1, int p2 );450 f( p1, p2 ) {} // int f( int p1, int p2 ) {}451 \end{lstlisting}452 453 As stated above, the two styles of declaration may appear together in the same block.454 Therefore, a programmer has the option of either continuing to use traditional C declarations or take advantage of the new style.455 Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX systems.456 547 457 548 … … 464 555 \begin{lstlisting} 465 556 y = (* int)x; 466 i = sizeof([ 5] * int);557 i = sizeof([ 10 ] * int); 467 558 \end{lstlisting} 468 559 & 469 560 \begin{lstlisting} 470 561 y = (int *)x; 471 i = sizeof(int *[ 5]);562 i = sizeof(int *[ 10 ]); 472 563 \end{lstlisting} 473 564 \end{tabular} … … 480 571 The point of the new syntax is to allow returning multiple values from a routine~\cite{CLU,Galletly96}, e.g.: 481 572 \begin{lstlisting} 482 ®[ int o1, int o2, char o3 ]®f( int i1, char i2, char i3 ) {483 §\emph{routine body}§573 [ int o1, int o2, char o3 ] f( int i1, char i2, char i3 ) { 574 @\emph{routine body}@ 484 575 } 485 576 \end{lstlisting} … … 492 583 Declaration qualifiers can only appear at the start of a routine definition, e.g.: 493 584 \begin{lstlisting} 494 extern [ int x ] g( int y ) { §\,§}585 extern [ int x ] g( int y ) {} 495 586 \end{lstlisting} 496 587 Lastly, if there are no output parameters or input parameters, the brackets and/or parentheses must still be specified; 497 588 in both cases the type is assumed to be void as opposed to old style C defaults of int return type and unknown parameter types, respectively, as in: 498 589 \begin{lstlisting} 499 [ §\,§] g();// no input or output parameters590 [ ] g(); // no input or output parameters 500 591 [ void ] g( void ); // no input or output parameters 501 592 \end{lstlisting} … … 509 600 \CFA style declarations cannot be used to declare parameters for K\&R style routine definitions because of the following ambiguity: 510 601 \begin{lstlisting} 511 int (*f(x))[ 5] int x; {}512 \end{lstlisting} 513 The string ``\lstinline@int (*f(x))[ 5 ]@'' declares a K\&R style routine of type returning a pointer to an array of 5 integers, while the string ``\lstinline@[ 5 ] int x@'' declares a \CFA style parameter x of type array of 5integers.602 int (*f(x))[ 10 ] int x; {} 603 \end{lstlisting} 604 The string ``\lstinline@int (*f(x))[ 10 ]@'' declares a K\&R style routine of type returning a pointer to an array of 10 integers, while the string ``\lstinline@[ 10 ] int x@'' declares a \CFA style parameter x of type array of 10 integers. 514 605 Since the strings overlap starting with the open bracket, \lstinline@[@, there is an ambiguous interpretation for the string. 515 606 As well, \CFA-style declarations cannot be used to declare parameters for C-style routine-definitions because of the following ambiguity: … … 530 621 \begin{lstlisting} 531 622 #define ptoa( n, d ) int (*n)[ d ] 532 int f( ptoa(p, 5) ) ... // expands to int f( int (*p)[ 5] )533 [ int ] f( ptoa(p, 5) ) ... // expands to [ int ] f( int (*p)[ 5] )623 int f( ptoa(p,10) ) ... // expands to int f( int (*p)[ 10 ] ) 624 [ int ] f( ptoa(p,10) ) ... // expands to [ int ] f( int (*p)[ 10 ] ) 534 625 \end{lstlisting} 535 626 Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms. … … 548 639 Because the value in the return variable is automatically returned when a \CFA routine terminates, the \lstinline@return@ statement \emph{does not} contain an expression, as in: 549 640 \begin{lstlisting} 550 ®[ int x ]®f() {641 [ int x ] f() { 551 642 ... x = 0; ... x = y; ... 552 ®return;®// implicitly return x643 return; // implicitly return x 553 644 } 554 645 \end{lstlisting} … … 606 697 for example, the following is incorrect: 607 698 \begin{lstlisting} 608 * [ int x ] f () fp; // routine name "f"is not allowed699 * [ int x ] f () fp; // routine name ``f'' is not allowed 609 700 \end{lstlisting} 610 701 … … 612 703 \section{Named and Default Arguments} 613 704 614 Named and default arguments~\cite{Hardgrave76} \footnote{705 Named and default arguments~\cite{Hardgrave76}.\footnote{ 615 706 Francez~\cite{Francez77} proposed a further extension to the named-parameter passing style, which specifies what type of communication (by value, by reference, by name) the argument is passed to the routine.} 616 707 are two mechanisms to simplify routine call. … … 773 864 \subsection{Type Nesting} 774 865 775 \CFA allows \Index{type nesting}, and type qualification of the nested types, where as C hoists\index{type hoisting} (refactors) nested types into the enclosing scope and has no type qualification.866 C allows \Index{type nesting}, but the nested types are hoisted\index{type!hoisting} (refactored) into the enclosing scope. 776 867 \begin{quote2} 777 868 \begin{tabular}{@{}l@{\hspace{30pt}}l|l@{}} … … 828 919 829 920 int fred() { 830 s.t.c = ®S.®R; // type qualification831 struct ®S.®T t = { ®S.®R, 1, 2 };832 enum ®S.®C c;833 union ®S.T.®U u;921 s.t.c = S.R; 922 struct S.T t = { S.R, 1, 2 }; 923 enum S.C c; 924 union S.T.U u; 834 925 } 835 926 \end{lstlisting} 836 927 \end{tabular} 837 928 \end{quote2} 838 In the left example in C, types \lstinline@C@, \lstinline@U@ and \lstinline@T@ are implicitly hoisted outside of type \lstinline@S@ into the containing block scope. 839 In the right example in \CFA, the types are not hoisted and accessed using the field-selection operator ``\lstinline@.@'' for type qualification, as does Java, rather than the \CC type-selection operator ``\lstinline@::@''. 929 930 \CFA is C \emph{incompatible} on this issue, and provides semantics similar to \CC. 931 Nested types are not hoisted and can be referenced using the field selection operator ``\lstinline@.@'', unlike the \CC scope-resolution operator ``\lstinline@::@''. 932 Given that nested types in C are equivalent to not using them, i.e., they are essentially useless, it is unlikely there are any realistic usages that break because of this incompatibility. 840 933 841 934 … … 850 943 which can be used to sort in ascending and descending order by locally redefining the less-than operator into greater-than. 851 944 \begin{lstlisting} 852 const unsigned int size = 5; 853 int ia[size]; 854 ... // assign values to array ia 855 qsort( ia, size ); // sort ascending order using builtin ?<? 856 { 857 ®int ?<?( int x, int y ) { return x > y; }® // nested routine 858 qsort( ia, size ); // sort descending order by local redefinition 859 } 860 \end{lstlisting} 861 862 Nested routines are not first-class, meaning a nested routine cannot be returned if it has references to variables in its enclosing blocks; 863 the only exception is references to the external block of the translation unit, as these variables persist for the duration of the program. 864 The following program in undefined in \CFA (and \lstinline@gcc@\index{gcc}) 865 \begin{lstlisting} 866 [* [int]( int )] foo() { // int (*foo())( int ) 867 int ®i® = 7; 868 int bar( int p ) { 869 ®i® += 1; // dependent on local variable 870 sout | ®i® | endl; 871 } 872 return bar; // undefined because of local dependence 873 } 874 int main() { 875 * [int](int) fp = foo(); // int (*fp)(int) 876 sout | fp( 3 ) | endl; 877 } 878 \end{lstlisting} 879 because 880 881 Currently, there are no \Index{lambda} expressions, i.e., unnamed routines because routine names are very important to properly select the correct routine. 945 const unsigned int size = 10; 946 int a[size]; 947 948 qsort( a, size ); // ascending order using built in ?<? 949 { // descending order by local redefinition 950 int ?<?( int a, int b ) { return a > b; } // nested routine 951 qsort( a, size ); 952 } 953 \end{lstlisting} 954 955 956 \section{Incompatible} 957 958 The following incompatibles exist between C and \CFA, and are similar to Annex C for \CC~\cite{ANSI14:C++}. 959 960 \begin{enumerate} 961 \item 962 Change type of character literal \lstinline@int@ to \lstinline@char@. 963 This change allows overloading differentiation argument type matching, e.g.: 964 \begin{lstlisting} 965 int function( int i ); 966 int function( char c ); 967 function( 'x' ); 968 \end{lstlisting} 969 It is preferable that this call match the second version of function rather than the first. \\ 970 Effect on original feature: Change to semantics of well-defined feature. ISO C programs which depend on 971 \begin{lstlisting} 972 sizeof('x') == sizeof(int) 973 \end{lstlisting} 974 will not work the same as C++ programs. \\ 975 Difficulty of converting: Simple. \\ 976 How widely used: Programs which depend upon sizeof('x') are probably rare. 977 978 \item 979 Change: String literals made \lstinline@const@ \\ 980 The type of a string literal is changed from \lstinline@array of char@ to \lstinline@array of const char@. 981 The type of a wide string literal is changed from \lstinline@array of wchar_t@ to \lstinline@array of const wchar_t@. \\ 982 Rationale: This avoids calling an inappropriate overloaded function, which might expect to be able to modify its argument. 983 Effect on original feature: Change to semantics of well-defined feature. \\ 984 Difficulty of converting: Simple syntactic transformation, because string literals can be converted to \lstinline@char*;@ (4.2). 985 The most common cases are handled by a new but deprecated standard conversion: 986 \begin{lstlisting} 987 char* p = "abc"; // valid in C, deprecated in C++ 988 char* q = expr ? "abc" : "de"; // valid in C, invalid in C++ 989 \end{lstlisting} 990 How widely used: Programs that have a legitimate reason to treat string literals as pointers to potentially modifiable memory are probably rare. 991 992 \item 993 Change: C++ does not have \emph{tentative definitions} as in C. 994 E.g., at file scope, 995 \begin{lstlisting} 996 int i; 997 int i; 998 \end{lstlisting} 999 is valid in C, invalid in C++. 1000 This makes it impossible to define mutually referential file-local static 1001 objects, if initializers are restricted to the syntactic forms of C. For example, 1002 \begin{lstlisting} 1003 struct X { int i; struct X *next; }; 1004 static struct X a; 1005 static struct X b = { 0, &a }; 1006 static struct X a = { 1, &b }; 1007 \end{lstlisting} 1008 Rationale: This avoids having different initialization rules for builtin types and userdefined types. 1009 Effect on original feature: Deletion of semantically welldefined feature. \\ 1010 Difficulty of converting: Semantic transformation. 1011 In C++, the initializer for one of a set of mutuallyreferential filelocal static objects must invoke a function call to achieve the initialization. 1012 How widely used: Seldom. 1013 1014 \item 1015 Change: A struct is a scope in C++, not in C 1016 Rationale: Class scope is crucial to C++, and a struct is a class. 1017 Effect on original feature: Change to semantics of well-defined feature. 1018 Difficulty of converting: Semantic transformation. 1019 How widely used: C programs use struct extremely frequently, but the change is only noticeable when 1020 struct, enumeration, or enumerator names are referred to outside the struct. The latter is probably 1021 rare. 1022 1023 \item 1024 Change: In C++, the name of a nested class is local to its enclosing class. 1025 In C the name of the nested class belongs to the same scope as the name of the outermost enclosing class 1026 Example: 1027 \begin{lstlisting} 1028 struct X { 1029 struct Y { /* ... */ } y; 1030 }; 1031 struct Y yy; // valid C, invalid C++ 1032 \end{lstlisting} 1033 Rationale: C++ classes have member functions which require that classes establish scopes. The C rule 1034 would leave classes as an incomplete scope mechanism which would prevent C++ programmers from maintaining 1035 locality within a class. A coherent set of scope rules for C++ based on the C rule would be very 1036 complicated and C++ programmers would be unable to predict reliably the meanings of nontrivial examples 1037 involving nested or local functions. 1038 Effect on original feature: Change of semantics of welldefined 1039 feature. 1040 Difficulty of converting: Semantic transformation. To make the struct type name visible in the scope of 1041 the enclosing struct, the struct tag could be declared in the scope of the enclosing struct, before the enclosing 1042 struct is defined. Example: 1043 \begin{lstlisting} 1044 struct Y; // struct Y and struct X are at the same scope 1045 struct X { 1046 struct Y { /* ... */ } y; 1047 }; 1048 \end{lstlisting} 1049 All the definitions of C struct types enclosed in other struct definitions and accessed outside the scope of 1050 the enclosing struct could be exported to the scope of the enclosing struct. Note: this is a consequence of 1051 the difference in scope rules, which is documented in 3.3. 1052 How widely used: Seldom. 1053 \end{enumerate} 882 1054 883 1055 … … 889 1061 The general syntax of a tuple is: 890 1062 \begin{lstlisting} 891 [ §\emph{exprlist}§]1063 [ $\emph{exprlist}$ ] 892 1064 \end{lstlisting} 893 1065 where \lstinline@$\emph{exprlist}$@ is a list of one or more expressions separated by commas. … … 909 1081 The general syntax of a tuple type is: 910 1082 \begin{lstlisting} 911 [ §\emph{typelist}§]1083 [ @\emph{typelist}@ ] 912 1084 \end{lstlisting} 913 1085 where \lstinline@$\emph{typelist}$@ is a list of one or more legal \CFA or C type specifications separated by commas, which may include other tuple type specifications. … … 917 1089 [ double, double, double ] 918 1090 [ * int, int * ] // mix of CFA and ANSI 919 [ * [ 5] int, * * char, * [ [ int, int ] ] (int, int) ]1091 [ * [ 10 ] int, * * char, * [ [ int, int ] ] (int, int) ] 920 1092 \end{lstlisting} 921 1093 Like tuples, tuple types may be nested, such as \lstinline@[ [ int, int ], int ]@, which is a 2-element tuple type whose first element is itself a tuple type. … … 1013 1185 First the right-hand tuple is flattened and then the values are assigned individually. 1014 1186 Flattening is also performed on tuple types. 1015 For example, the type \lstinline@[ int, [ int, int ], int ]@ can be coerced, using flattening, into the type \lstinline@[ int, int, int, int ]@.1187 For example, the type \lstinline@[ int, [ int, int ], int ]@ can be coerced, using flattening, into the type lstinline@[ int, int, int, int ]@. 1016 1188 1017 1189 A \newterm{structuring coercion} is the opposite of flattening; … … 1039 1211 Mass assignment has the following form: 1040 1212 \begin{lstlisting} 1041 [ §\emph{lvalue}§, ..., §\emph{lvalue}§ ] = §\emph{expr}§;1042 \end{lstlisting} 1043 The left-hand side is a tuple of \ emph{lvalues}, which is a list of expressions each yielding an address, i.e., any data object that can appear on the left-hand side of a conventional assignment statement.1213 [ @\emph{lvalue}@, ..., @\emph{lvalue}@ ] = @\emph{expr}@; 1214 \end{lstlisting} 1215 The left-hand side is a tuple of \lstinline@$\emph{lvalues}$@, which is a list of expressions each yielding an address, i.e., any data object that can appear on the left-hand side of a conventional assignment statement. 1044 1216 \lstinline@$\emph{expr}$@ is any standard arithmetic expression. 1045 1217 Clearly, the types of the entities being assigned must be type compatible with the value of the expression. … … 1078 1250 Multiple assignment has the following form: 1079 1251 \begin{lstlisting} 1080 [ §\emph{lvalue}§, . . ., §\emph{lvalue}§ ] = [ §\emph{expr}§, . . ., §\emph{expr}§];1081 \end{lstlisting} 1082 The left-hand side is a tuple of \ emph{lvalues}, and the right-hand side is a tuple of \emph{expr}s.1083 Each \ emph{expr} appearing on the righthand side of a multiple assignment statement is assigned to the corresponding \emph{lvalues}on the left-hand side of the statement using parallel semantics for each assignment.1252 [ @\emph{lvalue}@, . . ., @\emph{lvalue}@ ] = [ @\emph{expr}@, . . ., @\emph{expr}@ ]; 1253 \end{lstlisting} 1254 The left-hand side is a tuple of \lstinline@$\emph{lvalues}$@, and the right-hand side is a tuple of \lstinline@$\emph{expr}$@s. 1255 Each \lstinline@$\emph{expr}$@ appearing on the righthand side of a multiple assignment statement is assigned to the corresponding \lstinline@$\emph{lvalues}$@ on the left-hand side of the statement using parallel semantics for each assignment. 1084 1256 An example of multiple assignment is: 1085 1257 \begin{lstlisting} … … 1118 1290 Cascade assignment has the following form: 1119 1291 \begin{lstlisting} 1120 §\emph{tuple}§ = §\emph{tuple}§ = ... = §\emph{tuple}§;1292 @\emph{tuple}@ = @\emph{tuple}@ = ... = @\emph{tuple}@; 1121 1293 \end{lstlisting} 1122 1294 and it has the same parallel semantics as for mass and multiple assignment. … … 1136 1308 Its general form is: 1137 1309 \begin{lstlisting} 1138 §\emph{expr}§ . [ §\emph{fieldlist}§]1139 §\emph{expr}§ -> [ §\emph{fieldlist}§]1140 \end{lstlisting} 1141 \ emph{expr}is any expression yielding a value of type record, e.g., \lstinline@struct@, \lstinline@union@.1142 Each element of \ emph{ fieldlist} is an element of the record specified by \emph{expr}.1310 @\emph{expr}@ . [ @\emph{fieldlist}@ ] 1311 @\emph{expr}@ -> [ @\emph{fieldlist}@ ] 1312 \end{lstlisting} 1313 \lstinline@$\emph{expr}$@ is any expression yielding a value of type record, e.g., \lstinline@struct@, \lstinline@union@. 1314 Each element of \lstinline@$\emph{ fieldlist}$@ is an element of the record specified by \lstinline@$\emph{expr}$@. 1143 1315 A record-field tuple may be used anywhere a tuple can be used. An example of the use of a record-field tuple is 1144 1316 the following: … … 1180 1352 \multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1181 1353 \begin{lstlisting} 1182 ®L1:®for ( ... ) {1183 ®L2:®for ( ... ) {1184 ®L3:®for ( ... ) {1185 ... break ®L1®; ...1186 ... break ®L2®; ...1187 ... break ®L3®; // or break1354 L1: for ( ... ) { 1355 L2: for ( ... ) { 1356 L3: for ( ... ) { 1357 ... break L1; ... 1358 ... break L2; ... 1359 ... break L3; // or break 1188 1360 } 1189 1361 } … … 1210 1382 \multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1211 1383 \begin{lstlisting} 1212 ®L1®: for ( ... ) {1213 ®L2®: for ( ... ) {1214 ®L3®: for ( ... ) {1215 ... continue ®L1®; ...1216 ... continue ®L2®; ...1217 ... continue ®L3®; ...1384 L1: for ( ... ) { 1385 L2: for ( ... ) { 1386 L3: for ( ... ) { 1387 ... continue L1; ... 1388 ... continue L2; ... 1389 ... continue L3; ... 1218 1390 1219 1391 } … … 1451 1623 \begin{lstlisting} 1452 1624 switch ( i ) { 1453 ®case 1, 3, 5®:1625 case 1, 3, 5: 1454 1626 ... 1455 ®case 2, 4, 6®:1627 case 2, 4, 6: 1456 1628 ... 1457 1629 } … … 1462 1634 case 1: case 3 : case 5: 1463 1635 ... 1464 case 2: case 4 : case 6: 1636 case 2: case 4 : case 6: /* even values */ 1465 1637 ... 1466 1638 } … … 1483 1655 \begin{lstlisting} 1484 1656 switch ( i ) { 1485 ®case 1~5:®1657 case 1~5 1486 1658 ... 1487 ®case 10~15:®1659 case 10~15 1488 1660 ... 1489 1661 } … … 1500 1672 & 1501 1673 \begin{lstlisting} 1502 1503 1674 // 1, 2, 3, 4, 5 1504 1675 … … 1997 2168 1998 2169 1999 \section{Auto Type-Inferencing} 2000 2001 Auto type-inferencing occurs in a declaration where a variable's type is inferred from its initialization expression type. 2002 \begin{quote2} 2003 \begin{tabular}{@{}l@{\hspace{30pt}}ll@{}} 2004 \multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CC}} & \multicolumn{1}{c}{\lstinline@gcc@}\index{gcc} \\ 2005 \begin{lstlisting} 2006 2007 auto j = 3.0 * 4; 2008 int i; 2009 auto k = i; 2010 \end{lstlisting} 2011 & 2012 \begin{lstlisting} 2013 #define expr 3.0 * i 2014 typeof(expr) j = expr; 2015 int i; 2016 typeof(i) k = i; 2017 \end{lstlisting} 2018 & 2019 \begin{lstlisting} 2020 2021 // use type of initialization expression 2022 2023 // use type of primary variable 2024 \end{lstlisting} 2025 \end{tabular} 2026 \end{quote2} 2027 The two important capabilities are: 2028 \begin{itemize} 2029 \item 2030 preventing having to determine or write out long generic types, 2031 \item 2032 ensure secondary variables, related to a primary variable, always have the same type. 2033 \end{itemize} 2034 2035 In \CFA, \lstinline@typedef@ provides a mechanism to alias long type names with short ones, both globally and locally, but not eliminate the use of the short name. 2036 \lstinline@gcc@ provides \lstinline@typeof@ to declare a secondary variable from a primary variable. 2037 \CFA also relies heavily on the specification of the left-hand side of assignment for type inferencing, so in many cases it is crucial to specify the type of the left-hand side to select the correct type of the right-hand expression. 2038 Only for overloaded routines with the same return type is variable type-inferencing possible. 2039 Finally, \lstinline@auto@ presents the programming problem of tracking down a type when the type is actually needed. 2040 For example, given 2041 \begin{lstlisting} 2042 auto j = ®...® 2043 \end{lstlisting} 2044 and the need to write a routine to compute using \lstinline@j@ 2045 \begin{lstlisting} 2046 void rtn( ®...® parm ); 2047 rtn( j ); 2048 \end{lstlisting} 2049 A programmer must work backwards to determine the type of \lstinline@j@'s initialization expression, reconstructing the possibly long generic type-name. 2050 In this situation, having the type name or a short alias is very useful. 2051 2052 There is also the conundrum in type inferencing of when to \emph{\Index{brand}} a type. 2053 That is, when is the type of the variable more important than the type of its initialization expression. 2054 For example, if a change is made in an initialization expression, it can cause hundreds or thousands of cascading type changes and/or errors. 2055 At some point, a programmer wants the type of the variable to remain constant and the expression to be in error when it changes. 2056 2057 Given \lstinline@typedef@ and \lstinline@typeof@ in \CFA, and the strong need to use the type of left-hand side in inferencing, auto type-inferencing is not supported at this time. 2058 Should a significant need arise, this feature can be revisited. 2059 2060 2061 \section{Generics} 2170 \section{Generics } 2062 2171 2063 2172 \CFA supports parametric polymorphism to allow users to define generic functions and types. … … 2259 2368 2260 2369 try { 2261 throw 13;2370 throw 13; 2262 2371 } 2263 2372 catch(int e) { 2264 printf(.caught an exception: %d\n., e);2373 printf(.caught an exception: %d\n., e); 2265 2374 } 2266 2375 \end{lstlisting} … … 2348 2457 2349 2458 2350 \section{Syntactic Anomalies} 2351 2352 The number 0 and 1 are treated specially in \CFA, and can be redefined as variables. 2353 One syntactic anomaly is when a field in an structure is names 0 or 1: 2354 \begin{lstlisting} 2355 struct S { 2356 int 0, 1; 2357 } s; 2358 \end{lstlisting} 2359 The problem occurs in accesing these fields using the selection operation ``\lstinline@.@'': 2360 \begin{lstlisting} 2361 s.0 = 0; // ambiguity with floating constant .0 2362 s.1 = 1; // ambiguity with floating constant .1 2363 \end{lstlisting} 2364 To make this work, a space is required after the field selection: 2365 \begin{lstlisting} 2366 ®s.§\textvisiblespace§0® = 0; 2367 ®s.§\textvisiblespace§1® = 1; 2368 \end{lstlisting} 2369 While this sytact is awkward, it is unlikely many programers will name fields of a structure 0 or 1. 2370 Like the \CC lexical problem with closing template-syntax, e.g, \lstinline@Foo<Bar<int®>>®@, this issue can be solved with a more powerful lexer/parser. 2371 2372 There are several ambiguous cases with operator identifiers, e.g., \lstinline@int *?*?()@, where the string \lstinline@*?*?@ can be lexed as \lstinline@*@/\lstinline@?*?@ or \lstinline@*?@/\lstinline@*?@. 2373 Since it is common practise to put a unary operator juxtaposed to an identifier, e.g., \lstinline@*i@, users will be annoyed if they cannot do this with respect to operator identifiers. 2374 Even with this special hack, there are 5 general cases that cannot be handled. 2375 The first case is for the function-call identifier \lstinline@?()@: 2376 \begin{lstlisting} 2377 int *§\textvisiblespace§?()(); // declaration: space required after '*' 2378 *§\textvisiblespace§?()(); // expression: space required after '*' 2379 \end{lstlisting} 2380 Without the space, the string \lstinline@*?()@ is ambiguous without N character look ahead; 2381 it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument/parameter list. 2382 2383 The 4 remaining cases occur in expressions: 2384 \begin{lstlisting} 2385 i++§\textvisiblespace§?i:0; // space required before '?' 2386 i--§\textvisiblespace§?i:0; // space required before '?' 2387 i§\textvisiblespace§?++i:0; // space required after '?' 2388 i§\textvisiblespace§?--i:0; // space required after '?' 2389 \end{lstlisting} 2390 In the first two cases, the string \lstinline@i++?@ is ambiguous, where this string can be lexed as \lstinline@i@ / \lstinline@++?@ or \lstinline@i++@ / \lstinline@?@; 2391 it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument list. 2392 In the second two cases, the string \lstinline@?++x@ is ambiguous, where this string can be lexed as \lstinline@?++@ / \lstinline@x@ or \lstinline@?@ / y\lstinline@++x@; 2393 it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument list. 2459 \section{I/O Library} 2460 \label{s:IOLibrary} 2461 2462 The goal for \CFA I/O is to make I/O as simple as possible for the general case, while fully supporting polmorphism and user defined types in a consistent way. 2463 The general case is printing out a sequence of variables separated by whitespace. 2464 \begin{lstlisting} 2465 int x = 0, y = 1, z = 2; 2466 sout | x | y | z | endl; 2467 2468 cout << x << " " << y << " " << z << endl; 2469 \end{lstlisting} 2470 The \CC form takes almost twice as many characters. 2471 2472 The logical-or operator is used because it is the lowest priority overloadable operator, other than assignment. 2473 Therefore, most output expressions do not require parenthesis. 2474 \begin{lstlisting} 2475 int x = 0, y = 1, z = 2; 2476 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl; 2477 2478 cout << x * 3 << y + 1 << (z << 2) << (x == y) << (x | y) << (x || y) << (x > z ? 1 : 2) << endl; 2479 \end{lstlisting} 2480 2481 Finally, the logical-or operator has a link with the Shell pipe-operator for moving data, although data flows in the opposite direction. 2482 2483 \begin{figure} 2484 \begin{lstlisting}[mathescape=off] 2485 #include <fstream> 2486 2487 int main() { 2488 char c; 2489 short int si; 2490 unsigned short int usi; 2491 int i; 2492 unsigned int ui; 2493 long int li; 2494 unsigned long int uli; 2495 long long int lli; 2496 unsigned long long int ulli; 2497 float f; 2498 double d; 2499 long double ld; 2500 float _Complex fc; 2501 double _Complex dc; 2502 long double _Complex ldc; 2503 char s1[10], s2[10]; 2504 2505 ifstream in; 2506 open( &in, "read.data", "r" ); 2507 2508 &in | &c 2509 | &si | &usi | &i | &ui | &li | &uli | &lli | &ulli 2510 | &f | &d | &ld 2511 | &fc | &dc | &ldc 2512 | str( s1 ) | str( s2, 10 ); 2513 2514 sout | c | ' ' | endl 2515 | si | usi | i | ui | li | uli | lli | ulli | endl 2516 | f | d | ld | endl 2517 | f | "" | d | "" | ld | endl; 2518 2519 sepSet( sout, ", $" ); 2520 sout | fc | dc | ldc | endl 2521 | sepOn | s1 | sepOff | s2 | endl 2522 | s1 | "" | s2 | endl; 2523 } 2524 2525 $ cat read.data 2526 A 1 2 3 4 5 6 7 8 1.1 1.2 1.3 1.1+2.3 1.1-2.3 1.1-2.3 abc xyz 2527 $ a.out 2528 A 2529 1 2 3 4 5 6 7 8 2530 1.1 1.2 1.3 2531 1.11.21.3 2532 1.1+2.3i, $1.1-2.3i, $1.1-2.3i 2533 , $abcxyz 2534 abcxyz 2535 \end{lstlisting} 2536 \end{figure} 2537 2538 2539 \section{Standard Library} 2540 \label{s:StandardLibrary} 2541 2542 The goal of the \CFA standard-library is to wrap many of the existing C library-routines that are explicitly polymorphic into implicitly polymorphic versions. 2543 2544 2545 \subsection{malloc} 2546 2547 \begin{lstlisting} 2548 forall( otype T ) T * malloc( void ); 2549 forall( otype T ) T * malloc( char fill ); 2550 forall( otype T ) T * malloc( T * ptr, size_t size ); 2551 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill ); 2552 forall( otype T ) T * calloc( size_t size ); 2553 forall( otype T ) T * realloc( T * ptr, size_t size ); 2554 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ); 2555 2556 forall( otype T ) T * aligned_alloc( size_t alignment ); 2557 forall( otype T ) T * memalign( size_t alignment ); // deprecated 2558 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ); 2559 2560 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill 2561 forall( otype T ) T * memset( T * ptr ); // remove when default value available 2562 \end{lstlisting} 2563 2564 2565 \subsection{ato/strto} 2566 2567 \begin{lstlisting} 2568 int ato( const char * ptr ); 2569 unsigned int ato( const char * ptr ); 2570 long int ato( const char * ptr ); 2571 unsigned long int ato( const char * ptr ); 2572 long long int ato( const char * ptr ); 2573 unsigned long long int ato( const char * ptr ); 2574 float ato( const char * ptr ); 2575 double ato( const char * ptr ); 2576 long double ato( const char * ptr ); 2577 float _Complex ato( const char * ptr ); 2578 double _Complex ato( const char * ptr ); 2579 long double _Complex ato( const char * ptr ); 2580 2581 int strto( const char * sptr, char ** eptr, int base ); 2582 unsigned int strto( const char * sptr, char ** eptr, int base ); 2583 long int strto( const char * sptr, char ** eptr, int base ); 2584 unsigned long int strto( const char * sptr, char ** eptr, int base ); 2585 long long int strto( const char * sptr, char ** eptr, int base ); 2586 unsigned long long int strto( const char * sptr, char ** eptr, int base ); 2587 float strto( const char * sptr, char ** eptr ); 2588 double strto( const char * sptr, char ** eptr ); 2589 long double strto( const char * sptr, char ** eptr ); 2590 float _Complex strto( const char * sptr, char ** eptr ); 2591 double _Complex strto( const char * sptr, char ** eptr ); 2592 long double _Complex strto( const char * sptr, char ** eptr ); 2593 \end{lstlisting} 2594 2595 2596 \subsection{bsearch/qsort} 2597 2598 \begin{lstlisting} 2599 forall( otype T | { int ?<?( T, T ); } ) 2600 T * bsearch( const T key, const T * arr, size_t dimension ); 2601 2602 forall( otype T | { int ?<?( T, T ); } ) 2603 void qsort( const T * arr, size_t dimension ); 2604 \end{lstlisting} 2605 2606 2607 \subsection{abs} 2608 2609 \begin{lstlisting} 2610 char abs( char ); 2611 extern "C" { 2612 int abs( int ); // use default C routine for int 2613 } // extern 2614 long int abs( long int ); 2615 long long int abs( long long int ); 2616 float abs( float ); 2617 double abs( double ); 2618 long double abs( long double ); 2619 float _Complex abs( float _Complex ); 2620 double _Complex abs( double _Complex ); 2621 long double _Complex abs( long double _Complex ); 2622 \end{lstlisting} 2623 2624 2625 \subsection{random} 2626 2627 \begin{lstlisting} 2628 void randseed( long int s ); 2629 char random(); 2630 int random(); 2631 unsigned int random(); 2632 long int random(); 2633 unsigned long int random(); 2634 float random(); 2635 double random(); 2636 float _Complex random(); 2637 double _Complex random(); 2638 long double _Complex random(); 2639 \end{lstlisting} 2640 2641 2642 \subsection{min/max/swap} 2643 2644 \begin{lstlisting} 2645 forall( otype T | { int ?<?( T, T ); } ) 2646 T min( const T t1, const T t2 ); 2647 2648 forall( otype T | { int ?>?( T, T ); } ) 2649 T max( const T t1, const T t2 ); 2650 2651 forall( otype T ) 2652 void swap( T * t1, T * t2 ); 2653 \end{lstlisting} 2394 2654 2395 2655 … … 2416 2676 2417 2677 task creates a type with implicit locking, separate stack, and a thread 2418 2419 2678 2420 2679 \subsection{Monitors} … … 3317 3576 3318 3577 3319 \subsection [Comparing Key Features of CFA]{Comparing Key Features of \CFA}3578 \subsection{Comparing Key Features of \CFA} 3320 3579 3321 3580 … … 3516 3775 \multicolumn{1}{c|}{\textbf{\CFA/\CC}} & \multicolumn{1}{c|}{\textbf{Go}} & \multicolumn{1}{c}{\textbf{Rust}} \\ 3517 3776 \hline 3518 \begin{lstlisting} [boxpos=t]3777 \begin{lstlisting} 3519 3778 extern "C" { 3520 3779 #include <sys/types.h> … … 3523 3782 } 3524 3783 size_t fileSize( const char *path ) { 3525 st ruct stat s;3784 stat s; 3526 3785 stat(path, &s); 3527 3786 return s.st_size; … … 3529 3788 \end{lstlisting} 3530 3789 & 3531 \begin{lstlisting} [boxpos=t]3790 \begin{lstlisting} 3532 3791 /* 3533 3792 #cgo … … 3548 3807 \end{lstlisting} 3549 3808 & 3550 \begin{lstlisting} [boxpos=t]3809 \begin{lstlisting} 3551 3810 use libc::{c_int, size_t}; 3811 3812 // The following declarations are 3552 3813 // translated from sys/stat.h 3553 3814 #[repr(C)] … … 3557 3818 ... 3558 3819 } 3820 3559 3821 #[link(name = "libc")] 3560 3822 extern { … … 3562 3824 buf: *mut stat_t) -> c_int; 3563 3825 } 3826 3564 3827 fn fileSize(path: *const u8) -> size_t 3565 3828 { 3566 3829 unsafe { 3567 let mut buf: stat_t = uninit();3568 stat(path, &mut buf);3569 buf.st_size3830 let mut buf: stat_t = uninit(); 3831 stat(path, &mut buf); 3832 buf.st_size 3570 3833 } 3571 3834 } … … 3690 3953 3691 3954 3692 \begin{comment} 3693 \subsubsection{Modules / Packages} 3955 \subsubsection{Modules/Packages} 3694 3956 3695 3957 \begin{lstlisting} … … 3770 4032 } 3771 4033 \end{lstlisting} 3772 \end{comment}3773 3774 4034 3775 4035 \subsubsection{Parallel Tasks} … … 3927 4187 \end{flushleft} 3928 4188 3929 \lstset{basicstyle=\sf\relsize{-1}}3930 3931 3932 4189 \subsection{Summary of Language Comparison} 3933 4190 3934 4191 3935 \subsubsection [C++]{\CC}4192 \subsubsection{\CC} 3936 4193 3937 4194 \CC is a general-purpose programming language. … … 3998 4255 3999 4256 4000 \appendix4001 4002 4003 \section{Incompatible}4004 4005 The following incompatibles exist between C and \CFA, and are similar to Annex C for \CC~\cite{ANSI14:C++}.4006 4007 \begin{enumerate}4008 \item4009 Change type of character literal \lstinline@int@ to \lstinline@char@.4010 This change allows overloading differentiation argument type matching, e.g.:4011 \begin{lstlisting}4012 int function( int i );4013 int function( char c );4014 function( 'x' );4015 \end{lstlisting}4016 It is preferable that this call match the second version of function rather than the first. \\4017 Effect on original feature: Change to semantics of well-defined feature. ISO C programs which depend on4018 \begin{lstlisting}4019 sizeof('x') == sizeof(int)4020 \end{lstlisting}4021 will not work the same as C++ programs. \\4022 Difficulty of converting: Simple. \\4023 How widely used: Programs which depend upon sizeof('x') are probably rare.4024 4025 \item4026 Change: String literals made \lstinline@const@ \\4027 The type of a string literal is changed from \lstinline@array of char@ to \lstinline@array of const char@.4028 The type of a wide string literal is changed from \lstinline@array of wchar_t@ to \lstinline@array of const wchar_t@. \\4029 Rationale: This avoids calling an inappropriate overloaded function, which might expect to be able to modify its argument.4030 Effect on original feature: Change to semantics of well-defined feature. \\4031 Difficulty of converting: Simple syntactic transformation, because string literals can be converted to \lstinline@char*;@ (4.2).4032 The most common cases are handled by a new but deprecated standard conversion:4033 \begin{lstlisting}4034 char* p = "abc"; // valid in C, deprecated in C++4035 char* q = expr ? "abc" : "de"; // valid in C, invalid in C++4036 \end{lstlisting}4037 How widely used: Programs that have a legitimate reason to treat string literals as pointers to potentially modifiable memory are probably rare.4038 4039 \item4040 Change: C++ does not have \emph{tentative definitions} as in C.4041 E.g., at file scope,4042 \begin{lstlisting}4043 int i;4044 int i;4045 \end{lstlisting}4046 is valid in C, invalid in C++.4047 This makes it impossible to define mutually referential file-local static4048 objects, if initializers are restricted to the syntactic forms of C. For example,4049 \begin{lstlisting}4050 struct X { int i; struct X *next; };4051 static struct X a;4052 static struct X b = { 0, &a };4053 static struct X a = { 1, &b };4054 \end{lstlisting}4055 Rationale: This avoids having different initialization rules for builtin types and userdefined types.4056 Effect on original feature: Deletion of semantically welldefined feature. \\4057 Difficulty of converting: Semantic transformation.4058 In C++, the initializer for one of a set of mutuallyreferential filelocal static objects must invoke a function call to achieve the initialization.4059 How widely used: Seldom.4060 4061 \item4062 Change: A struct is a scope in C++, not in C \\4063 Rationale: Class scope is crucial to C++, and a struct is a class. \\4064 Effect on original feature: Change to semantics of well-defined feature. \\4065 Difficulty of converting: Semantic transformation. \\4066 How widely used: C programs use struct extremely frequently, but the change is only noticeable when struct, enumeration, or enumerator names are referred to outside the struct.4067 The latter is probably rare.4068 4069 \CFA is C \emph{incompatible} on this issue, and provides semantics similar to \CC.4070 Nested types are not hoisted and can be referenced using the field selection operator ``\lstinline@.@'', unlike the \CC scope-resolution operator ``\lstinline@::@''.4071 Given that nested types in C are equivalent to not using them, i.e., they are essentially useless, it is unlikely there are any realistic usages that break because of this incompatibility.4072 4073 \item4074 Change: In C++, the name of a nested class is local to its enclosing class.4075 In C the name of the nested class belongs to the same scope as the name of the outermost enclosing class4076 Example:4077 \begin{lstlisting}4078 struct X {4079 struct Y { /* ... */ } y;4080 };4081 struct Y yy; // valid C, invalid C++4082 \end{lstlisting}4083 Rationale: C++ classes have member functions which require that classes establish scopes.4084 The C rule would leave classes as an incomplete scope mechanism which would prevent C++ programmers from maintaining locality within a class. A coherent set of scope rules for C++ based on the C rule would be very complicated and C++ programmers would be unable to predict reliably the meanings of nontrivial examples involving nested or local functions.4085 Effect on original feature: Change of semantics of welldefined feature.4086 Difficulty of converting: Semantic transformation. To make the struct type name visible in the scope of the enclosing struct, the struct tag could be declared in the scope of the enclosing struct, before the enclosing struct is defined. Example:4087 \begin{lstlisting}4088 struct Y; // struct Y and struct X are at the same scope4089 struct X {4090 struct Y { /* ... */ } y;4091 };4092 \end{lstlisting}4093 All the definitions of C struct types enclosed in other struct definitions and accessed outside the scope of the enclosing struct could be exported to the scope of the enclosing struct.4094 Note: this is a consequence of the difference in scope rules, which is documented in 3.3.4095 How widely used: Seldom.4096 \end{enumerate}4097 4098 4099 \section{I/O Library}4100 \label{s:IOLibrary}4101 \index{input/output library}4102 4103 The goal for \CFA I/O is to make I/O as simple as possible for the general case, while fully supporting polmorphism and user defined types in a consistent way.4104 The general case is printing out a sequence of variables separated by whitespace.4105 \begin{quote2}4106 \begin{tabular}{@{}l@{\hspace{30pt}}l@{}}4107 \multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\4108 \begin{lstlisting}4109 int x = 0, y = 1, z = 2;4110 ®sout® ®|® x ®|® y ®|® z ®| endl®;4111 \end{lstlisting}4112 &4113 \begin{lstlisting}4114 4115 cout << x << " " << y << " " << z << endl;4116 \end{lstlisting}4117 \end{tabular}4118 \end{quote2}4119 The \CFA form is half as many characters, and is similar to \Index{Python} I/O with respect to implicit separators.4120 4121 The logical-or operator is used because it is the lowest-priority overloadable operator, other than assignment.4122 Therefore, fewer output expressions require parenthesis.4123 \begin{quote2}4124 \begin{tabular}{@{}ll@{}}4125 \textbf{\CFA:}4126 &4127 \begin{lstlisting}4128 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;4129 \end{lstlisting}4130 \\4131 \textbf{\CC:}4132 &4133 \begin{lstlisting}4134 cout << x * 3 << y + 1 << (z << 2) << (x == y) << (x | y) << (x || y) << (x > z ? 1 : 2) << endl;4135 \end{lstlisting}4136 \end{tabular}4137 \end{quote2}4138 Finally, the logical-or operator has a link with the Shell pipe-operator for moving data, although data flows in the opposite direction.4139 4140 The implicit seperator\index{I/O separator} character (space/blank) is a separator not a terminator.4141 The rules for implicitly adding the separator are:4142 \begin{enumerate}4143 \item4144 A seperator does not appear at the start or end of a line.4145 \begin{lstlisting}[belowskip=0pt]4146 sout | 1 | 2 | 3 | endl;4147 \end{lstlisting}4148 \begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]4149 1 2 34150 \end{lstlisting}4151 \item4152 A seperator does not appear before or after a character literal or variable.4153 \begin{lstlisting}4154 sout | '1' | '2' | '3' | endl;4155 1234156 \end{lstlisting}4157 \item4158 A seperator does not appear before or after a null (empty) C string4159 \begin{lstlisting}4160 sout | 1 | "" | 2 | "" | 3 | endl;4161 1234162 \end{lstlisting}4163 which is a local mechanism to disable insertion of the separator character.4164 \item4165 A seperator does not appear before a C string starting with the (extended) \Index{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off]@([{$£¥¡¿«@4166 %$4167 \begin{lstlisting}[mathescape=off]4168 sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x $" | 4 | "x £" | 5 | "x ¥" | 6 | "x ¡" | 7 | "x ¿" | 8 | "x «" | 9 | endl;4169 \end{lstlisting}4170 %$4171 \begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]4172 x (1 x [2 x {3 x $4 x £5 x ¥6 x ¡7 x ¿8 x «94173 \end{lstlisting}4174 %$4175 \item4176 A seperator does not appear after a C string ending with the (extended) \Index{ASCII}\index{ASCII!extended} characters: \lstinline@,.:;!?)]}%¢»@4177 \begin{lstlisting}[belowskip=0pt]4178 sout | 1 | ", x" | 2 | ". x" | 3 | ": x" | 4 | "; x" | 5 | "! x" | 6 | "? x" | 7 | ") x" | 8 | "] x" | 9 | "} x"4179 | 10 | "% x" | 11 | "¢ x" | 12 | "» x" | endl;4180 \end{lstlisting}4181 \begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]4182 1, x 2. x 3: x 4; x 5! x 6? x 7) x 8] x 9} x 10% x 11¢ 12»4183 \end{lstlisting}4184 \item4185 A seperator does not appear before or after a C string begining/ending with the \Index{ASCII} quote or whitespace characters: \lstinline[showspaces=true]@`'" \t\v\f\r\n@4186 \begin{lstlisting}[belowskip=0pt]4187 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x" | "x " | 4 | " x" | "x\t" | 1 | "\tx" | endl;4188 \end{lstlisting}4189 \begin{lstlisting}[mathescape=off,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]4190 x`1`x'2'x"3"x x 4 x x 1 x4191 \end{lstlisting}4192 \end{enumerate}4193 The following \CC-style \Index{manipulator}s allow further control over implicit seperation.4194 \begin{lstlisting}[mathescape=off,belowskip=0pt]4195 sout | sepOn | 1 | 2 | 3 | sepOn | endl; // separator at start of line4196 \end{lstlisting}4197 \begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]4198 1 2 34199 \end{lstlisting}4200 \begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]4201 sout | 1 | sepOff | 2 | 3 | endl; // turn off implicit separator temporarily4202 \end{lstlisting}4203 \begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]4204 12 34205 \end{lstlisting}4206 \begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]4207 sout | sepDisable | 1 | 2 | 3 | endl; // turn off implicit separation, affects all subsequent prints4208 \end{lstlisting}4209 \begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]4210 1234211 \end{lstlisting}4212 \begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]4213 sout | 1 | sepOn | 2 | 3 | endl; // turn on implicit separator temporarily4214 \end{lstlisting}4215 \begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]4216 1 234217 \end{lstlisting}4218 \begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]4219 sout | sepEnable | 1 | 2 | 3 | endl; // turn on implicit separation, affects all subsequent prints4220 \end{lstlisting}4221 \begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]4222 1 2 34223 \end{lstlisting}4224 \begin{lstlisting}[mathescape=off,aboveskip=0pt,aboveskip=0pt,belowskip=0pt]4225 sepSet( sout, ", $" ); // change separator from " " to ", $"4226 sout | 1 | 2 | 3 | endl;4227 \end{lstlisting}4228 %$4229 \begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt]4230 1, $2, $34231 \end{lstlisting}4232 %$4233 \begin{comment}4234 #include <fstream>4235 4236 int main() {4237 int x = 3, y = 5, z = 7;4238 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;4239 sout | 1 | 2 | 3 | endl;4240 sout | '1' | '2' | '3' | endl;4241 sout | 1 | "" | 2 | "" | 3 | endl;4242 sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x $" | 4 | "x £" | 5 | "x ¥" | 6 | "x ¡" | 7 | "x ¿" | 8 | "x «" | 9 | endl;4243 sout | 1 | ", x" | 2 | ". x" | 3 | ": x" | 4 | "; x" | 5 | "! x" | 6 | "? x" | 7 | ") x" | 8 | "] x" | 9 | "} x"4244 | 10 | "% x" | 11 | "¢ x" | 12 | "» x" | endl;4245 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x" | "x " | 4 | " x" | "x\t" | 1 | "\tx" | endl;4246 sout | sepOn | 1 | 2 | 3 | sepOn | endl; // separator at start of line4247 sout | 1 | sepOff | 2 | 3 | endl; // turn off implicit separator temporarily4248 sout | sepDisable | 1 | 2 | 3 | endl; // turn off implicit separation, affects all subsequent prints4249 sout | 1 | sepOn | 2 | 3 | endl; // turn on implicit separator temporarily4250 sout | sepEnable | 1 | 2 | 3 | endl; // turn on implicit separation, affects all subsequent prints4251 sepSet( sout, ", $" ); // change separator from " " to ", $"4252 sout | 1 | 2 | 3 | endl;4253 4254 }4255 4256 // Local Variables: //4257 // tab-width: 4 //4258 // End: //4259 \end{comment}4260 %$4261 4262 4263 \section{Standard Library}4264 \label{s:StandardLibrary}4265 4266 The goal of the \CFA standard-library is to wrap many of the existing C library-routines that are explicitly polymorphic into implicitly polymorphic versions.4267 4268 4269 \subsection{malloc}4270 4271 \begin{lstlisting}4272 forall( otype T ) T * malloc( void );§\indexc{malloc}§4273 forall( otype T ) T * malloc( char fill );4274 forall( otype T ) T * malloc( T * ptr, size_t size );4275 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill );4276 forall( otype T ) T * calloc( size_t nmemb );§\indexc{calloc}§4277 forall( otype T ) T * realloc( T * ptr, size_t size );§\indexc{ato}§4278 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );4279 4280 forall( otype T ) T * aligned_alloc( size_t alignment );§\indexc{ato}§4281 forall( otype T ) T * memalign( size_t alignment ); // deprecated4282 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );4283 4284 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill4285 forall( otype T ) T * memset( T * ptr ); // remove when default value available4286 \end{lstlisting}4287 4288 4289 \subsection{ato / strto}4290 4291 \begin{lstlisting}4292 int ato( const char * ptr );§\indexc{ato}§4293 unsigned int ato( const char * ptr );4294 long int ato( const char * ptr );4295 unsigned long int ato( const char * ptr );4296 long long int ato( const char * ptr );4297 unsigned long long int ato( const char * ptr );4298 float ato( const char * ptr );4299 double ato( const char * ptr );4300 long double ato( const char * ptr );4301 float _Complex ato( const char * ptr );4302 double _Complex ato( const char * ptr );4303 long double _Complex ato( const char * ptr );4304 4305 int strto( const char * sptr, char ** eptr, int base );4306 unsigned int strto( const char * sptr, char ** eptr, int base );4307 long int strto( const char * sptr, char ** eptr, int base );4308 unsigned long int strto( const char * sptr, char ** eptr, int base );4309 long long int strto( const char * sptr, char ** eptr, int base );4310 unsigned long long int strto( const char * sptr, char ** eptr, int base );4311 float strto( const char * sptr, char ** eptr );4312 double strto( const char * sptr, char ** eptr );4313 long double strto( const char * sptr, char ** eptr );4314 float _Complex strto( const char * sptr, char ** eptr );4315 double _Complex strto( const char * sptr, char ** eptr );4316 long double _Complex strto( const char * sptr, char ** eptr );4317 \end{lstlisting}4318 4319 4320 \subsection{bsearch / qsort}4321 4322 \begin{lstlisting}4323 forall( otype T | { int ?<?( T, T ); } )4324 T * bsearch( const T key, const T * arr, size_t dimension );§\indexc{bsearch}§4325 4326 forall( otype T | { int ?<?( T, T ); } )4327 void qsort( const T * arr, size_t dimension );§\indexc{qsort}§4328 \end{lstlisting}4329 4330 4331 \subsection{abs}4332 4333 \begin{lstlisting}4334 char abs( char );§\indexc{abs}§4335 int abs( int );4336 long int abs( long int );4337 long long int abs( long long int );4338 float abs( float );4339 double abs( double );4340 long double abs( long double );4341 float abs( float _Complex );4342 double abs( double _Complex );4343 long double abs( long double _Complex );4344 \end{lstlisting}4345 4346 4347 \subsection{random}4348 4349 \begin{lstlisting}4350 void rand48seed( long int s );§\indexc{rand48seed}§4351 char rand48();§\indexc{rand48}§4352 int rand48();4353 unsigned int rand48();4354 long int rand48();4355 unsigned long int rand48();4356 float rand48();4357 double rand48();4358 float _Complex rand48();4359 double _Complex rand48();4360 long double _Complex rand48();4361 \end{lstlisting}4362 4363 4364 \subsection{min / max / swap}4365 4366 \begin{lstlisting}4367 forall( otype T | { int ?<?( T, T ); } )4368 T min( const T t1, const T t2 );§\indexc{min}§4369 4370 forall( otype T | { int ?>?( T, T ); } )4371 T max( const T t1, const T t2 );§\indexc{max}§4372 4373 forall( otype T )4374 void swap( T * t1, T * t2 );§\indexc{swap}§4375 \end{lstlisting}4376 4377 4378 \section{Math Library}4379 \label{s:Math Library}4380 4381 The goal of the \CFA math-library is to wrap many of the existing C math library-routines that are explicitly polymorphic into implicitly polymorphic versions.4382 4383 4384 \subsection{General}4385 4386 \begin{lstlisting}4387 float fabs( float );§\indexc{fabs}§4388 double fabs( double );4389 long double fabs( long double );4390 float cabs( float _Complex );4391 double cabs( double _Complex );4392 long double cabs( long double _Complex );4393 4394 float ?%?( float, float );§\indexc{fmod}§4395 float fmod( float, float );4396 double ?%?( double, double );4397 double fmod( double, double );4398 long double ?%?( long double, long double );4399 long double fmod( long double, long double );4400 4401 float remainder( float, float );§\indexc{remainder}§4402 double remainder( double, double );4403 long double remainder( long double, long double );4404 4405 [ int, float ] remquo( float, float );§\indexc{remquo}§4406 float remquo( float, float, int * );4407 [ int, double ] remquo( double, double );4408 double remquo( double, double, int * );4409 [ int, long double ] remquo( long double, long double );4410 long double remquo( long double, long double, int * );4411 4412 [ int, float ] div( float, float ); // alternative name for remquo4413 float div( float, float, int * );§\indexc{div}§4414 [ int, double ] div( double, double );4415 double div( double, double, int * );4416 [ int, long double ] div( long double, long double );4417 long double div( long double, long double, int * );4418 4419 float fma( float, float, float );§\indexc{fma}§4420 double fma( double, double, double );4421 long double fma( long double, long double, long double );4422 4423 float fdim( float, float );§\indexc{fdim}§4424 double fdim( double, double );4425 long double fdim( long double, long double );4426 4427 float nan( const char * );§\indexc{nan}§4428 double nan( const char * );4429 long double nan( const char * );4430 \end{lstlisting}4431 4432 4433 \subsection{Exponential}4434 4435 \begin{lstlisting}4436 float exp( float );§\indexc{exp}§4437 double exp( double );4438 long double exp( long double );4439 float _Complex exp( float _Complex );4440 double _Complex exp( double _Complex );4441 long double _Complex exp( long double _Complex );4442 4443 float exp2( float );§\indexc{exp2}§4444 double exp2( double );4445 long double exp2( long double );4446 float _Complex exp2( float _Complex );4447 double _Complex exp2( double _Complex );4448 long double _Complex exp2( long double _Complex );4449 4450 float expm1( float );§\indexc{expm1}§4451 double expm1( double );4452 long double expm1( long double );4453 4454 float log( float );§\indexc{log}§4455 double log( double );4456 long double log( long double );4457 float _Complex log( float _Complex );4458 double _Complex log( double _Complex );4459 long double _Complex log( long double _Complex );4460 4461 float log2( float );§\indexc{log2}§4462 double log2( double );4463 long double log2( long double );4464 float _Complex log2( float _Complex );4465 double _Complex log2( double _Complex );4466 long double _Complex log2( long double _Complex );4467 4468 float log10( float );§\indexc{log10}§4469 double log10( double );4470 long double log10( long double );4471 float _Complex log10( float _Complex );4472 double _Complex log10( double _Complex );4473 long double _Complex log10( long double _Complex );4474 4475 float log1p( float );§\indexc{log1p}§4476 double log1p( double );4477 long double log1p( long double );4478 4479 int ilogb( float );§\indexc{ilogb}§4480 int ilogb( double );4481 int ilogb( long double );4482 4483 float logb( float );§\indexc{logb}§4484 double logb( double );4485 long double logb( long double );4486 \end{lstlisting}4487 4488 4489 \subsection{Power}4490 4491 \begin{lstlisting}4492 float sqrt( float );§\indexc{sqrt}§4493 double sqrt( double );4494 long double sqrt( long double );4495 float _Complex sqrt( float _Complex );4496 double _Complex sqrt( double _Complex );4497 long double _Complex sqrt( long double _Complex );4498 4499 float cbrt( float );§\indexc{cbrt}§4500 double cbrt( double );4501 long double cbrt( long double );4502 4503 float hypot( float, float );§\indexc{hypot}§4504 double hypot( double, double );4505 long double hypot( long double, long double );4506 4507 float pow( float, float );§\indexc{pow}§4508 double pow( double, double );4509 long double pow( long double, long double );4510 float _Complex pow( float _Complex, float _Complex );4511 double _Complex pow( double _Complex, double _Complex );4512 long double _Complex pow( long double _Complex, long double _Complex );4513 \end{lstlisting}4514 4515 4516 \subsection{Trigonometric}4517 4518 \begin{lstlisting}4519 float sin( float );§\indexc{sin}§4520 double sin( double );4521 long double sin( long double );4522 float _Complex sin( float _Complex );4523 double _Complex sin( double _Complex );4524 long double _Complex sin( long double _Complex );4525 4526 float cos( float );§\indexc{cos}§4527 double cos( double );4528 long double cos( long double );4529 float _Complex cos( float _Complex );4530 double _Complex cos( double _Complex );4531 long double _Complex cos( long double _Complex );4532 4533 float tan( float );§\indexc{tan}§4534 double tan( double );4535 long double tan( long double );4536 float _Complex tan( float _Complex );4537 double _Complex tan( double _Complex );4538 long double _Complex tan( long double _Complex );4539 4540 float asin( float );§\indexc{asin}§4541 double asin( double );4542 long double asin( long double );4543 float _Complex asin( float _Complex );4544 double _Complex asin( double _Complex );4545 long double _Complex asin( long double _Complex );4546 4547 float acos( float );§\indexc{acos}§4548 double acos( double );4549 long double acos( long double );4550 float _Complex acos( float _Complex );4551 double _Complex acos( double _Complex );4552 long double _Complex acos( long double _Complex );4553 4554 float atan( float );§\indexc{atan}§4555 double atan( double );4556 long double atan( long double );4557 float _Complex atan( float _Complex );4558 double _Complex atan( double _Complex );4559 long double _Complex atan( long double _Complex );4560 4561 float atan2( float, float );§\indexc{atan2}§4562 double atan2( double, double );4563 long double atan2( long double, long double );4564 4565 float atan( float, float ); // alternative name for atan24566 double atan( double, double );§\indexc{atan}§4567 long double atan( long double, long double );4568 \end{lstlisting}4569 4570 4571 \subsection{Hyperbolic}4572 4573 \begin{lstlisting}4574 float sinh( float );§\indexc{sinh}§4575 double sinh( double );4576 long double sinh( long double );4577 float _Complex sinh( float _Complex );4578 double _Complex sinh( double _Complex );4579 long double _Complex sinh( long double _Complex );4580 4581 float cosh( float );§\indexc{cosh}§4582 double cosh( double );4583 long double cosh( long double );4584 float _Complex cosh( float _Complex );4585 double _Complex cosh( double _Complex );4586 long double _Complex cosh( long double _Complex );4587 4588 float tanh( float );§\indexc{tanh}§4589 double tanh( double );4590 long double tanh( long double );4591 float _Complex tanh( float _Complex );4592 double _Complex tanh( double _Complex );4593 long double _Complex tanh( long double _Complex );4594 4595 float asinh( float );§\indexc{asinh}§4596 double asinh( double );4597 long double asinh( long double );4598 float _Complex asinh( float _Complex );4599 double _Complex asinh( double _Complex );4600 long double _Complex asinh( long double _Complex );4601 4602 float acosh( float );§\indexc{acosh}§4603 double acosh( double );4604 long double acosh( long double );4605 float _Complex acosh( float _Complex );4606 double _Complex acosh( double _Complex );4607 long double _Complex acosh( long double _Complex );4608 4609 float atanh( float );§\indexc{atanh}§4610 double atanh( double );4611 long double atanh( long double );4612 float _Complex atanh( float _Complex );4613 double _Complex atanh( double _Complex );4614 long double _Complex atanh( long double _Complex );4615 \end{lstlisting}4616 4617 4618 \subsection{Error / Gamma}4619 4620 \begin{lstlisting}4621 float erf( float );§\indexc{erf}§4622 double erf( double );4623 long double erf( long double );4624 float _Complex erf( float _Complex );4625 double _Complex erf( double _Complex );4626 long double _Complex erf( long double _Complex );4627 4628 float erfc( float );§\indexc{erfc}§4629 double erfc( double );4630 long double erfc( long double );4631 float _Complex erfc( float _Complex );4632 double _Complex erfc( double _Complex );4633 long double _Complex erfc( long double _Complex );4634 4635 float lgamma( float );§\indexc{lgamma}§4636 double lgamma( double );4637 long double lgamma( long double );4638 float lgamma( float, int * );4639 double lgamma( double, int * );4640 long double lgamma( long double, int * );4641 4642 float tgamma( float );§\indexc{tgamma}§4643 double tgamma( double );4644 long double tgamma( long double );4645 \end{lstlisting}4646 4647 4648 \subsection{Nearest Integer}4649 4650 \begin{lstlisting}4651 float floor( float );§\indexc{floor}§4652 double floor( double );4653 long double floor( long double );4654 4655 float ceil( float );§\indexc{ceil}§4656 double ceil( double );4657 long double ceil( long double );4658 4659 float trunc( float );§\indexc{trunc}§4660 double trunc( double );4661 long double trunc( long double );4662 4663 float rint( float );§\indexc{rint}§4664 long double rint( long double );4665 long int rint( float );4666 long int rint( double );4667 long int rint( long double );4668 long long int rint( float );4669 long long int rint( double );4670 long long int rint( long double );4671 4672 long int lrint( float );§\indexc{lrint}§4673 long int lrint( double );4674 long int lrint( long double );4675 long long int llrint( float );4676 long long int llrint( double );4677 long long int llrint( long double );4678 4679 float nearbyint( float );§\indexc{nearbyint}§4680 double nearbyint( double );4681 long double nearbyint( long double );4682 4683 float round( float );§\indexc{round}§4684 long double round( long double );4685 long int round( float );4686 long int round( double );4687 long int round( long double );4688 long long int round( float );4689 long long int round( double );4690 long long int round( long double );4691 4692 long int lround( float );§\indexc{lround}§4693 long int lround( double );4694 long int lround( long double );4695 long long int llround( float );4696 long long int llround( double );4697 long long int llround( long double );4698 \end{lstlisting}4699 4700 4701 \subsection{Manipulation}4702 4703 \begin{lstlisting}4704 float copysign( float, float );§\indexc{copysign}§4705 double copysign( double, double );4706 long double copysign( long double, long double );4707 4708 float frexp( float, int * );§\indexc{frexp}§4709 double frexp( double, int * );4710 long double frexp( long double, int * );4711 4712 float ldexp( float, int );§\indexc{ldexp}§4713 double ldexp( double, int );4714 long double ldexp( long double, int );4715 4716 [ float, float ] modf( float );§\indexc{modf}§4717 float modf( float, float * );4718 [ double, double ] modf( double );4719 double modf( double, double * );4720 [ long double, long double ] modf( long double );4721 long double modf( long double, long double * );4722 4723 float nextafter( float, float );§\indexc{nextafter}§4724 double nextafter( double, double );4725 long double nextafter( long double, long double );4726 4727 float nexttoward( float, long double );§\indexc{nexttoward}§4728 double nexttoward( double, long double );4729 long double nexttoward( long double, long double );4730 4731 float scalbn( float, int );§\indexc{scalbn}§4732 double scalbn( double, int );4733 long double scalbn( long double, int );4734 4735 float scalbln( float, long int );§\indexc{scalbln}§4736 double scalbln( double, long int );4737 long double scalbln( long double, long int );4738 \end{lstlisting}4739 4740 4741 \section{Rational Numbers}4742 \label{s:RationalNumbers}4743 4744 Rational numbers are numbers written as a ratio, i.e., as a fraction, where the numerator (top number) and the denominator (bottom number) are whole numbers.4745 When creating and computing with rational numbers, results are constantly reduced to keep the numerator and denominator as small as possible.4746 4747 \begin{lstlisting}4748 // implementation4749 struct Rational {§\indexc{Rational}§4750 long int numerator, denominator; // invariant: denominator > 04751 }; // Rational4752 4753 // constants4754 extern struct Rational 0;4755 extern struct Rational 1;4756 4757 // constructors4758 Rational rational();4759 Rational rational( long int n );4760 Rational rational( long int n, long int d );4761 4762 // getter/setter for numerator/denominator4763 long int numerator( Rational r );4764 long int numerator( Rational r, long int n );4765 long int denominator( Rational r );4766 long int denominator( Rational r, long int d );4767 4768 // comparison4769 int ?==?( Rational l, Rational r );4770 int ?!=?( Rational l, Rational r );4771 int ?<?( Rational l, Rational r );4772 int ?<=?( Rational l, Rational r );4773 int ?>?( Rational l, Rational r );4774 int ?>=?( Rational l, Rational r );4775 4776 // arithmetic4777 Rational -?( Rational r );4778 Rational ?+?( Rational l, Rational r );4779 Rational ?-?( Rational l, Rational r );4780 Rational ?*?( Rational l, Rational r );4781 Rational ?/?( Rational l, Rational r );4782 4783 // conversion4784 double widen( Rational r );4785 Rational narrow( double f, long int md );4786 4787 // I/O4788 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );4789 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );4790 \end{lstlisting}4791 4792 4793 4257 \bibliographystyle{plain} 4794 \bibliography{ cfa}4258 \bibliography{/usr/local/bibliographies/pl.bib} 4795 4259 4796 4260
Note:
See TracChangeset
for help on using the changeset viewer.