Changes in doc/refrat/refrat.tex [e945826:a752883]
- File:
-
- 1 edited
-
doc/refrat/refrat.tex (modified) (165 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/refrat/refrat.tex
re945826 ra752883 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 %% refrat.tex --9 %%10 %% Author : Peter A. Buhr11 %% Created On : Wed Apr 6 14:52:25 201612 %% Last Modified By : Peter A. Buhr13 %% Last Modified On : Sat Apr 30 13:45:40 201614 %% Update Count : 2915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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]{report} … … 27 5 28 6 % Latex packages used in the document. 7 29 8 \usepackage{fullpage,times} 30 9 \usepackage{xspace} … … 32 11 \usepackage{listings} 33 12 \usepackage{comment} 34 \usepackage{latexsym} % \Box35 \usepackage{mathptmx} % better math font with "times"13 \usepackage{latexsym} % \Box 14 \usepackage{mathptmx} % better math font with "times" 36 15 \usepackage[pagewise]{lineno} 37 16 \renewcommand{\linenumberfont}{\scriptsize\sffamily} … … 42 21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 43 22 23 % Names used in the document. 24 25 \newcommand{\CFA}{C$\forall$\xspace} % set language symbolic name 26 \newcommand{\CFL}{Cforall\xspace} % set language text name 27 \newcommand{\CC}{C\kern-.1em\hbox{+\kern-.25em+}\xspace} % CC symbolic name 28 \def\c11{ISO/IEC C} % C11 name (cannot have numbers in latex command name) 29 30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 31 44 32 % Bespoke macros used in the document. 45 \input{common} 46 47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 48 49 \setcounter{secnumdepth}{3} % number subsubsections 50 \setcounter{tocdepth}{3} % subsubsections in table of contents 33 34 \makeatletter 35 % allow escape sequence in lstinline 36 %\usepackage{etoolbox} 37 %\patchcmd{\lsthk@TextStyle}{\let\lst@DefEsc\@empty}{}{}{\errmessage{failed to patch}} 38 39 \renewcommand\small{% 40 \@setfontsize\small{8.5}{11}% 41 \abovedisplayskip 8.5pt \@plus 3pt \@minus 4pt 42 \abovedisplayshortskip \z@ \@plus 2pt 43 \belowdisplayshortskip 4pt \@plus 2pt \@minus 2pt 44 \def\@listi{\leftmargin\leftmargini 45 \topsep 4pt \@plus 2pt \@minus 2pt 46 \parsep 2pt \@pluspt \@minuspt 47 \itemsep \parsep}% 48 \belowdisplayskip \abovedisplayskip 49 } 50 \usepackage{relsize} % must be after change to small 51 52 \renewcommand{\labelitemi}{{\raisebox{0.25ex}{\footnotesize$\bullet$}}} 53 \renewenvironment{itemize}{\begin{list}{\labelitemi}{\topsep=5pt\itemsep=5pt\parsep=0pt}}{\end{list}} 54 55 % Reduce size of chapter/section titles 56 \def\@makechapterhead#1{% 57 \vspace*{50\p@}% 58 {\parindent \z@ \raggedright \normalfont 59 \ifnum \c@secnumdepth >\m@ne 60 \large\bfseries \@chapapp\space \thechapter 61 \par\nobreak 62 \vskip 5\p@ 63 \fi 64 \interlinepenalty\@M 65 \Large \bfseries #1\par\nobreak 66 \vskip 50\p@ 67 }} 68 \def\@makeschapterhead#1{% 69 \vspace*{50\p@}% 70 {\parindent \z@ \raggedright 71 \normalfont 72 \interlinepenalty\@M 73 \Large \bfseries #1\par\nobreak 74 \vskip 50\p@ 75 }} 76 \renewcommand\section{\@startsection{section}{1}{\z@}{-3.0ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\large\bfseries}} 77 \renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}} 78 \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}} 79 \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}} 80 81 % index macros 82 \newcommand{\italic}[1]{\emph{\hyperpage{#1}}} 83 \newcommand{\definition}[1]{\textbf{\hyperpage{#1}}} 84 \newcommand{\see}[1]{\emph{see} #1} 85 86 % Define some commands that produce formatted index entries suitable for cross-references. 87 % ``\spec'' produces entries for specifications of entities. ``\impl'' produces entries for their 88 % implementations, and ``\use'' for their uses. 89 90 % \newcommand{\bold}[1]{{\bf #1}} 91 % \def\spec{\@bsphack\begingroup 92 % \def\protect##1{\string##1\space}\@sanitize 93 % \@wrxref{|bold}} 94 \def\impl{\@bsphack\begingroup 95 \def\protect##1{\string##1\space}\@sanitize 96 \@wrxref{|definition}} 97 \newcommand{\indexcode}[1]{{\lstinline$#1$}} 98 \def\use{\@bsphack\begingroup 99 \def\protect##1{\string##1\space}\@sanitize 100 \@wrxref{|hyperpage}} 101 \def\@wrxref#1#2{\let\thepage\relax 102 \xdef\@gtempa{\write\@indexfile{\string 103 \indexentry{#2@{\lstinline$#2$}#1}{\thepage}}}\endgroup\@gtempa 104 \if@nobreak \ifvmode\nobreak\fi\fi\@esphack} 105 %\newcommand{\use}[1]{\index{#1@{\lstinline$#1$}}} 106 %\newcommand{\impl}[1]{\index{\protect#1@{\lstinline$\protect#1$}|definition}} 107 108 % inline text and lowercase index: \Index{inline and lowercase index text} 109 % inline text and as-in index: \Index[as-is index text]{inline text} 110 % inline text but index with different as-is text: \Index[index text]{inline text} 111 \newcommand{\Index}{\@ifstar\@sIndex\@Index} 112 \newcommand{\@Index}[2][\@empty]{\lowercase{\def\temp{#2}}#2\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi} 113 \newcommand{\@sIndex}[2][\@empty]{#2\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi} 114 \makeatother 115 116 % blocks and titles 117 \newenvironment{rationale}{% 118 \begin{quotation}\noindent$\Box$\enspace 119 }{% 120 \hfill\enspace$\Box$\end{quotation} 121 }% 122 \newcommand{\define}[1]{\emph{#1\/}\index{#1}} 123 \newcommand{\rewrite}{\(\Rightarrow\)} 124 \newcommand{\rewriterules}{\paragraph{Rewrite Rules}~\par\noindent} 125 \newcommand{\examples}{\paragraph{Examples}~\par\noindent} 126 \newcommand{\semantics}{\paragraph{Semantics}~\par\noindent} 127 \newcommand{\constraints}{\paragraph{Constraints}~\par\noindent} 128 \newcommand{\predefined}{\paragraph{Predefined Identifiers}~\par\noindent} 129 130 % BNF macros 131 \def\syntax{\paragraph{Syntax}\trivlist\parindent=.5in\item[\hskip.5in]} 132 \let\endsyntax=\endtrivlist 133 \newcommand{\lhs}[1]{\par{\emph{#1:}}\index{#1@{\emph{#1}}|italic}} 134 \newcommand{\rhs}{\hfil\break\hbox{\hskip1in}} 135 \newcommand{\oldlhs}[1]{\emph{#1: \ldots}\index{#1@{\emph{#1}}|italic}} 136 \newcommand{\nonterm}[1]{\emph{#1\/}\index{#1@{\emph{#1}}|italic}} 137 \newcommand{\opt}{$_{opt}$\ } 138 139 % adjust varioref package with default "section" and "page" titles, and optional title with faraway page numbers 140 % \VRef{label} => Section 2.7, \VPageref{label} => page 17 141 % \VRef[Figure]{label} => Figure 3.4, \VPageref{label} => page 17 142 \renewcommand{\reftextfaceafter}{\unskip} 143 \renewcommand{\reftextfacebefore}{\unskip} 144 \renewcommand{\reftextafter}{\unskip} 145 \renewcommand{\reftextbefore}{\unskip} 146 \renewcommand{\reftextfaraway}[1]{\unskip, p.~\pageref{#1}} 147 \renewcommand{\reftextpagerange}[2]{\unskip, pp.~\pageref{#1}--\pageref{#2}} 148 \newcommand{\VRef}[2][Section]{\ifx#1\@empty\else{#1}\nobreakspace\fi\vref{#2}} 149 \newcommand{\VPageref}[2][page]{\ifx#1\@empty\else{#1}\nobreakspace\fi\pageref{#2}} 150 151 % CFA based on ANSI C 152 \lstdefinelanguage{CFA}[ANSI]{C}% 153 {morekeywords={asm,_Alignas,_Alignof,_At,_Atomic,_Bool,catch,catchResume,choose,_Complex,trait,disable,dtype,enable, 154 fallthru,finally,forall,ftype,_Generic,_Imaginary,inline,lvalue,_Noreturn,otype,restrict,_Static_assert, 155 _Thread_local,throw,throwResume,try,}, 156 }% 157 158 \lstset{ 159 language=CFA, 160 columns=flexible, 161 basicstyle=\sf\relsize{-1}, 162 tabsize=4, 163 xleftmargin=\parindent, 164 escapechar=@, 165 keepspaces=true, 166 showstringspaces=false, 167 showlines=true, 168 }% 169 170 \makeatletter 171 % replace/adjust listings characters that look bad in sanserif 172 \lst@CCPutMacro 173 \lst@ProcessOther{"2D}{\lst@ttfamily{-{}}{{\ttfamily\upshape -}}} % replace minus 174 \lst@ProcessOther{"3C}{\lst@ttfamily{<}{\texttt{<}}} % replace less than 175 \lst@ProcessOther{"3E}{\lst@ttfamily{<}{\texttt{>}}} % replace greater than 176 \lst@ProcessOther{"5E}{\raisebox{0.4ex}{$\scriptstyle\land\,$}} % replace circumflex 177 \lst@ProcessLetter{"5F}{\lst@ttfamily{\char95}{{\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}}} % replace underscore 178 \lst@ProcessOther{"7E}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}} % replace tilde 179 %\lst@ProcessOther{"7E}{\raisebox{-.4ex}[1ex][0pt]{\textasciitilde}} % lower tilde 180 \@empty\z@\@empty 181 \makeatother 182 183 \setcounter{secnumdepth}{3} % number subsubsections 184 \setcounter{tocdepth}{3} % subsubsections in table of contents 51 185 \makeindex 52 186 … … 55 189 \begin{document} 56 190 \pagestyle{headings} 57 \linenumbers % comment out to turn off line numbering191 \linenumbers % comment out to turn off line numbering 58 192 59 193 \title{\Huge 60 \vspace*{1in}61 194 \CFA (\CFL) Reference Manual and Rationale 62 195 }% title … … 93 226 94 227 This document is a reference manual and rationale for \CFA, a polymorphic extension of the C programming language. 95 It makes frequent reference to the {\c11} standard \cite{ C11}, and occasionally compares \CFA to {\CC} \cite{C++}.228 It makes frequent reference to the {\c11} standard \cite{ANS:C11}, and occasionally compares \CFA to {\CC} \cite{c++}. 96 229 97 230 The manual deliberately imitates the ordering of the {\c11} standard (although the section numbering differs). … … 131 264 \CFA's scope rules differ from C's in one major respect: a declaration of an identifier may overload\index{overloading} outer declarations of lexically identical identifiers in the same 132 265 \Index{name space}, instead of hiding them. 133 The outer declaration is hidden if the two declarations have \Index{compatible type}, or if one declares an array type and the other declares a pointer type and the element type and pointed-at type are compatible, or if one has function type and the other is a pointer to a compatible function type, or if one declaration is a \lstinline @type@\use{type} or134 \lstinline @typedef@\use{typedef} declaration and the other is not. The outer declaration becomes266 The outer declaration is hidden if the two declarations have \Index{compatible type}, or if one declares an array type and the other declares a pointer type and the element type and pointed-at type are compatible, or if one has function type and the other is a pointer to a compatible function type, or if one declaration is a \lstinline$type$\use{type} or 267 \lstinline$typedef$\use{typedef} declaration and the other is not. The outer declaration becomes 135 268 \Index{visible} when the scope of the inner declaration terminates. 136 269 \begin{rationale} 137 Hence, a \CFA program can declare an \lstinline @int v@ and a \lstinline@float v@in the same scope;270 Hence, a \CFA program can declare an \lstinline$int v$ and a \lstinline$float v$ in the same scope; 138 271 a {\CC} program can not. 139 272 \end{rationale} … … 149 282 Identifiers with \Index{no linkage} always denote unique entities. 150 283 \begin{rationale} 151 A \CFA program can declare an \lstinline @extern int v@ and an \lstinline@extern float v@;284 A \CFA program can declare an \lstinline$extern int v$ and an \lstinline$extern float v$; 152 285 a C program cannot. 153 286 \end{rationale} … … 172 305 \end{lstlisting} 173 306 174 The type parameters in an instantiation of a generic type must satisfy any constraints in the forall specifier on the type generator declaration, e.g., \lstinline @sumable@.307 The type parameters in an instantiation of a generic type must satisfy any constraints in the forall specifier on the type generator declaration, e.g., \lstinline$sumable$. 175 308 The instantiation then has the semantics that would result if the type parameters were substituted into the type generator declaration by macro substitution. 176 309 … … 233 366 In \CFA, these conversions play a role in overload resolution, and collectively are called the \define{safe arithmetic conversion}s. 234 367 235 Let \ lstinline@int$_r$@ and \lstinline@unsigned$_r$@be the signed and unsigned integer types with integer conversion rank\index{integer conversion rank}\index{rank|see{integer conversion rank}} $r$.236 Let \ lstinline@unsigned$_{mr}$@be the unsigned integer type with maximal rank.368 Let \(int_r\) and \(unsigned_r\) be the signed and unsigned integer types with integer conversion rank\index{integer conversion rank}\index{rank|see{integer conversion rank}} $r$. 369 Let \(unsigned_{mr}\) be the unsigned integer type with maximal rank. 237 370 238 371 The following conversions are \emph{direct} safe arithmetic conversions. … … 241 374 The \Index{integer promotion}s. 242 375 \item 243 For every rank $r$ greater than or equal to the rank of \lstinline @int@, conversion from \lstinline@int$_r$@ to \lstinline@unsigned$_r$@.244 \item 245 For every rank $r$ greater than or equal to the rank of \lstinline @int@, where \lstinline@int$_{r+1}$@ exists and can represent all values of \lstinline@unsigned$_r$@, conversion from \lstinline@unsigned$_r$@ to \lstinline@int$_{r+1}$@.246 \item 247 Conversion from \ lstinline@unsigned$_{mr}$@ to \lstinline@float@.376 For every rank $r$ greater than or equal to the rank of \lstinline$int$, conversion from \(int_r\) to \(unsigned_r\). 377 \item 378 For every rank $r$ greater than or equal to the rank of \lstinline$int$, where \(int_{r+1}\) exists and can represent all values of \(unsigned_r\), conversion from \(unsigned_r\) to \(int_{r+1}\). 379 \item 380 Conversion from \(unsigned_{mr}\) to \lstinline$float$. 248 381 \item 249 382 Conversion from an enumerated type to its compatible integer type. 250 383 \item 251 Conversion from \lstinline @float@ to \lstinline@double@, and from \lstinline@double@ to \lstinline@long double@.252 \item 253 Conversion from \lstinline @float _Complex@ to \lstinline@double _Complex@, and from \lstinline@double _Complex@ to \lstinline@long double _Complex@.384 Conversion from \lstinline$float$ to \lstinline$double$, and from \lstinline$double$ to \lstinline$long double$. 385 \item 386 Conversion from \lstinline$float _Complex$ to \lstinline$double _Complex$, and from \lstinline$double _Complex$ to \lstinline$long double _Complex$. 254 387 \begin{sloppypar} 255 388 \item 256 Conversion from \lstinline @float _Imaginary@ to \lstinline@double _Imaginary@, and from \lstinline@double _Imaginary@ to \lstinline@long double _Imaginary@, if the implementation supports imaginary types.389 Conversion from \lstinline$float _Imaginary$ to \lstinline$double _Imaginary$, and from \lstinline$double _Imaginary$ to \lstinline$long double$ \lstinline$_Imaginary$, if the implementation supports imaginary types. 257 390 \end{sloppypar} 258 391 \end{itemize} 259 392 260 If type \lstinline @T@ can be converted to type \lstinline@U@ by a safe direct arithmetic conversion and type \lstinline@U@ can be converted to type \lstinline@V@ by a safe arithmetic conversion, then the conversion from \lstinline@T@ to type \lstinline@V@is an \emph{indirect} safe arithmetic conversion.393 If type \lstinline$T$ can be converted to type \lstinline$U$ by a safe direct arithmetic conversion and type \lstinline$U$ can be converted to type \lstinline$V$ by a safe arithmetic conversion, then the conversion from \lstinline$T$ to type \lstinline$V$ is an \emph{indirect} safe arithmetic conversion. 261 394 262 395 \begin{rationale} … … 281 414 int x, y; 282 415 }; 283 void move_by( struct point * p1, struct point * p2 ) { §\impl{move_by}§416 void move_by( struct point * p1, struct point * p2 ) {@\impl{move_by}@ 284 417 p1->x += p2.x; 285 418 p1->y += p2.y; … … 291 424 move_to( &cp1, &cp2 ); 292 425 \end{lstlisting} 293 Thanks to implicit conversion, the two arguments that \lstinline @move_by()@receives are pointers to294 \lstinline @cp1@'s second member and \lstinline@cp2@'s second member.426 Thanks to implicit conversion, the two arguments that \lstinline$move_by()$ receives are pointers to 427 \lstinline$cp1$'s second member and \lstinline$cp2$'s second member. 295 428 296 429 … … 334 467 a direct safe arithmetic conversion; 335 468 \item 336 from any object type or incomplete type to \lstinline @void@;337 \item 338 from a pointer to any non-\lstinline @void@ type to a pointer to \lstinline@void@;469 from any object type or incomplete type to \lstinline$void$; 470 \item 471 from a pointer to any non-\lstinline$void$ type to a pointer to \lstinline$void$; 339 472 \item 340 473 from a pointer to any type to a pointer to a more qualified version of the type\index{qualified type}; … … 347 480 Conversions that are not safe conversions are \define{unsafe conversion}s. 348 481 \begin{rationale} 349 As in C, there is an implicit conversion from \lstinline @void *@to any pointer type.482 As in C, there is an implicit conversion from \lstinline$void *$ to any pointer type. 350 483 This is clearly dangerous, and {\CC} does not have this implicit conversion. 351 484 \CFA\index{deficiencies!void * conversion} keeps it, in the interest of remaining as pure a superset of C as possible, but discourages it by making it unsafe. … … 373 506 \begin{itemize} 374 507 \item 375 The cost of an implicit conversion from \lstinline @int@ to \lstinline@long@is 1.376 The cost of an implicit conversion from \lstinline @long@ to \lstinline@double@ is 3, because it is defined in terms of conversions from \lstinline@long@ to \lstinline@unsigned long@, then to \lstinline@float@, and then to \lstinline@double@.377 378 \item 379 If \lstinline @int@ can represent all the values of \lstinline@unsigned short@, then the cost of an implicit conversion from \lstinline@unsigned short@ to \lstinline@unsigned@is 2:380 \lstinline @unsigned short@ to \lstinline@int@ to \lstinline@unsigned@.381 Otherwise, \lstinline @unsigned short@ is converted directly to \lstinline@unsigned@, and the cost is 1.382 383 \item 384 If \lstinline @long@ can represent all the values of \lstinline@unsigned@, then the conversion cost of \lstinline@unsigned@ to \lstinline@long@is 1.508 The cost of an implicit conversion from \lstinline$int$ to \lstinline$long$ is 1. 509 The cost of an implicit conversion from \lstinline$long$ to \lstinline$double$ is 3, because it is defined in terms of conversions from \lstinline$long$ to \lstinline$unsigned long$, then to \lstinline$float$, and then to \lstinline$double$. 510 511 \item 512 If \lstinline$int$ can represent all the values of \lstinline$unsigned short$, then the cost of an implicit conversion from \lstinline$unsigned short$ to \lstinline$unsigned$ is 2: 513 \lstinline$unsigned short$ to \lstinline$int$ to \lstinline$unsigned$. 514 Otherwise, \lstinline$unsigned short$ is converted directly to \lstinline$unsigned$, and the cost is 1. 515 516 \item 517 If \lstinline$long$ can represent all the values of \lstinline$unsigned$, then the conversion cost of \lstinline$unsigned$ to \lstinline$long$ is 1. 385 518 Otherwise, the conversion is an unsafe conversion, and its conversion cost is undefined. 386 519 \end{itemize} … … 390 523 \begin{syntax} 391 524 \oldlhs{keyword} 392 \rhs \lstinline @forall@393 \rhs \lstinline @lvalue@394 \rhs \lstinline @trait@395 \rhs \lstinline @dtype@396 \rhs \lstinline @ftype@397 \rhs \lstinline @otype@525 \rhs \lstinline$forall$ 526 \rhs \lstinline$lvalue$ 527 \rhs \lstinline$trait$ 528 \rhs \lstinline$dtype$ 529 \rhs \lstinline$ftype$ 530 \rhs \lstinline$type$ 398 531 \end{syntax} 399 532 … … 402 535 403 536 \CFA allows operator \Index{overloading} by associating operators with special function identifiers. 404 Furthermore, the constants ``\lstinline @0@'' and ``\lstinline@1@'' have special status for many of C's data types (and for many programmer-defined data types as well), so \CFA treats them as overloadable identifiers.537 Furthermore, the constants ``\lstinline$0$'' and ``\lstinline$1$'' have special status for many of C's data types (and for many programmer-defined data types as well), so \CFA treats them as overloadable identifiers. 405 538 Programmers can use these identifiers to declare functions and objects that implement operators and constants for their own types. 406 539 … … 411 544 \begin{syntax} 412 545 \oldlhs{identifier} 413 \rhs \lstinline @0@414 \rhs \lstinline @1@546 \rhs \lstinline$0$ 547 \rhs \lstinline$1$ 415 548 \end{syntax} 416 549 417 \index{constant identifiers}\index{identifiers!for constants} The tokens ``\lstinline @0@''\impl{0} and ``\lstinline@1@''\impl{1} are identifiers.550 \index{constant identifiers}\index{identifiers!for constants} The tokens ``\lstinline$0$''\impl{0} and ``\lstinline$1$''\impl{1} are identifiers. 418 551 No other tokens defined by the rules for integer constants are considered to be identifiers. 419 552 \begin{rationale} 420 Why ``\lstinline @0@'' and ``\lstinline@1@''? Those integers have special status in C.553 Why ``\lstinline$0$'' and ``\lstinline$1$''? Those integers have special status in C. 421 554 All scalar types can be incremented and decremented, which is defined in terms of adding or subtracting 1. 422 The operations ``\lstinline @&&@'', ``\lstinline@||@'', and ``\lstinline@!@'' can be applied to any scalar arguments, and are defined in terms of comparison against 0.555 The operations ``\lstinline$&&$'', ``\lstinline$||$'', and ``\lstinline$!$'' can be applied to any scalar arguments, and are defined in terms of comparison against 0. 423 556 A \nonterm{constant-expression} that evaluates to 0 is effectively compatible with every pointer type. 424 557 425 558 In C, the integer constants 0 and 1 suffice because the integer promotion rules can convert them to any arithmetic type, and the rules for pointer expressions treat constant expressions evaluating to 0 as a special case. 426 559 However, user-defined arithmetic types often need the equivalent of a 1 or 0 for their functions or operators, polymorphic functions often need 0 and 1 constants of a type matching their polymorphic parameters, and user-defined pointer-like types may need a null value. 427 Defining special constants for a user-defined type is more efficient than defining a conversion to the type from \lstinline @_Bool@.428 429 Why \emph{just} ``\lstinline @0@'' and ``\lstinline@1@''? Why not other integers? No other integers have special status in C.430 A facility that let programmers declare specific constants---``\lstinline @const Rational 12@'', for instance---would not be much of an improvement.560 Defining special constants for a user-defined type is more efficient than defining a conversion to the type from \lstinline$_Bool$. 561 562 Why \emph{just} ``\lstinline$0$'' and ``\lstinline$1$''? Why not other integers? No other integers have special status in C. 563 A facility that let programmers declare specific constants---``\lstinline$const Rational 12$'', for instance---would not be much of an improvement. 431 564 Some facility for defining the creation of values of programmer-defined types from arbitrary integer tokens would be needed. 432 565 The complexity of such a feature doesn't seem worth the gain. … … 444 577 \begin{tabular}[t]{ll} 445 578 %identifier & operation \\ \hline 446 \lstinline @?[?]@& subscripting \impl{?[?]}\\447 \lstinline @?()@& function call \impl{?()}\\448 \lstinline @?++@& postfix increment \impl{?++}\\449 \lstinline @?--@& postfix decrement \impl{?--}\\450 \lstinline @++?@& prefix increment \impl{++?}\\451 \lstinline @--?@& prefix decrement \impl{--?}\\452 \lstinline @*?@& dereference \impl{*?}\\453 \lstinline @+?@& unary plus \impl{+?}\\454 \lstinline @-?@& arithmetic negation \impl{-?}\\455 \lstinline @~?@& bitwise negation \impl{~?}\\456 \lstinline @!?@& logical complement \impl{"!?}\\457 \lstinline @?*?@& multiplication \impl{?*?}\\458 \lstinline @?/?@& division \impl{?/?}\\579 \lstinline$?[?]$ & subscripting \impl{?[?]}\\ 580 \lstinline$?()$ & function call \impl{?()}\\ 581 \lstinline$?++$ & postfix increment \impl{?++}\\ 582 \lstinline$?--$ & postfix decrement \impl{?--}\\ 583 \lstinline$++?$ & prefix increment \impl{++?}\\ 584 \lstinline$--?$ & prefix decrement \impl{--?}\\ 585 \lstinline$*?$ & dereference \impl{*?}\\ 586 \lstinline$+?$ & unary plus \impl{+?}\\ 587 \lstinline$-?$ & arithmetic negation \impl{-?}\\ 588 \lstinline$~?$ & bitwise negation \impl{~?}\\ 589 \lstinline$!?$ & logical complement \impl{"!?}\\ 590 \lstinline$?*?$ & multiplication \impl{?*?}\\ 591 \lstinline$?/?$ & division \impl{?/?}\\ 459 592 \end{tabular}\hfil 460 593 \begin{tabular}[t]{ll} 461 594 %identifier & operation \\ \hline 462 \lstinline @?%?@& remainder \impl{?%?}\\463 \lstinline @?+?@& addition \impl{?+?}\\464 \lstinline @?-?@& subtraction \impl{?-?}\\465 \lstinline @?<<?@& left shift \impl{?<<?}\\466 \lstinline @?>>?@& right shift \impl{?>>?}\\467 \lstinline @?<?@& less than \impl{?<?}\\468 \lstinline @?<=?@& less than or equal \impl{?<=?}\\469 \lstinline @?>=?@& greater than or equal \impl{?>=?}\\470 \lstinline @?>?@& greater than \impl{?>?}\\471 \lstinline @?==?@& equality \impl{?==?}\\472 \lstinline @?!=?@& inequality \impl{?"!=?}\\473 \lstinline @?&?@& bitwise AND \impl{?&?}\\595 \lstinline$?%?$ & remainder \impl{?%?}\\ 596 \lstinline$?+?$ & addition \impl{?+?}\\ 597 \lstinline$?-?$ & subtraction \impl{?-?}\\ 598 \lstinline$?<<?$ & left shift \impl{?<<?}\\ 599 \lstinline$?>>?$ & right shift \impl{?>>?}\\ 600 \lstinline$?<?$ & less than \impl{?<?}\\ 601 \lstinline$?<=?$ & less than or equal \impl{?<=?}\\ 602 \lstinline$?>=?$ & greater than or equal \impl{?>=?}\\ 603 \lstinline$?>?$ & greater than \impl{?>?}\\ 604 \lstinline$?==?$ & equality \impl{?==?}\\ 605 \lstinline$?!=?$ & inequality \impl{?"!=?}\\ 606 \lstinline$?&?$ & bitwise AND \impl{?&?}\\ 474 607 \end{tabular}\hfil 475 608 \begin{tabular}[t]{ll} 476 609 %identifier & operation \\ \hline 477 \lstinline @?^?@& exclusive OR \impl{?^?}\\478 \lstinline @?|?@& inclusive OR \impl{?"|?}\\479 \lstinline @?=?@& simple assignment \impl{?=?}\\480 \lstinline @?*=?@& multiplication assignment \impl{?*=?}\\481 \lstinline @?/=?@& division assignment \impl{?/=?}\\482 \lstinline @?%=?@& remainder assignment \impl{?%=?}\\483 \lstinline @?+=?@& addition assignment \impl{?+=?}\\484 \lstinline @?-=?@& subtraction assignment \impl{?-=?}\\485 \lstinline @?<<=?@& left-shift assignment \impl{?<<=?}\\486 \lstinline @?>>=?@& right-shift assignment \impl{?>>=?}\\487 \lstinline @?&=?@& bitwise AND assignment \impl{?&=?}\\488 \lstinline @?^=?@& exclusive OR assignment \impl{?^=?}\\489 \lstinline @?|=?@& inclusive OR assignment \impl{?"|=?}\\610 \lstinline$?^?$ & exclusive OR \impl{?^?}\\ 611 \lstinline$?|?$ & inclusive OR \impl{?"|?}\\ 612 \lstinline$?=?$ & simple assignment \impl{?=?}\\ 613 \lstinline$?*=?$ & multiplication assignment \impl{?*=?}\\ 614 \lstinline$?/=?$ & division assignment \impl{?/=?}\\ 615 \lstinline$?%=?$ & remainder assignment \impl{?%=?}\\ 616 \lstinline$?+=?$ & addition assignment \impl{?+=?}\\ 617 \lstinline$?-=?$ & subtraction assignment \impl{?-=?}\\ 618 \lstinline$?<<=?$ & left-shift assignment \impl{?<<=?}\\ 619 \lstinline$?>>=?$ & right-shift assignment \impl{?>>=?}\\ 620 \lstinline$?&=?$ & bitwise AND assignment \impl{?&=?}\\ 621 \lstinline$?^=?$ & exclusive OR assignment \impl{?^=?}\\ 622 \lstinline$?|=?$ & inclusive OR assignment \impl{?"|=?}\\ 490 623 \end{tabular} 491 624 \hfil … … 502 635 503 636 \begin{rationale} 504 The use of ``\lstinline @?@'' in identifiers means that some C programs are not \CFA programs. For instance, the sequence of characters ``\lstinline@(i < 0)?--i:i@'' is legal in a C program, but a505 \CFA compiler detects a syntax error because it treats ``\lstinline @?--@'' as an identifier, not as the two tokens ``\lstinline@?@'' and ``\lstinline@--@''.637 The use of ``\lstinline$?$'' in identifiers means that some C programs are not \CFA programs. For instance, the sequence of characters ``\lstinline$(i < 0)?--i:i$'' is legal in a C program, but a 638 \CFA compiler detects a syntax error because it treats ``\lstinline$?--$'' as an identifier, not as the two tokens ``\lstinline$?$'' and ``\lstinline$--$''. 506 639 \end{rationale} 507 640 … … 510 643 \begin{itemize} 511 644 \item 512 The logical operators ``\lstinline @&&@'' and ``\lstinline@||@'', and the conditional operator513 ``\lstinline @?:@''.645 The logical operators ``\lstinline$&&$'' and ``\lstinline$||$'', and the conditional operator 646 ``\lstinline$?:$''. 514 647 These operators do not always evaluate their operands, and hence can not be properly defined by functions unless some mechanism like call-by-name is added to the language. 515 Note that the definitions of ``\lstinline @&&@'' and ``\lstinline@||@'' say that they work by checking that their arguments are unequal to 0, so defining ``\lstinline@!=@'' and ``\lstinline@0@'' for user-defined types is enough to allow them to be used in logical expressions.648 Note that the definitions of ``\lstinline$&&$'' and ``\lstinline$||$'' say that they work by checking that their arguments are unequal to 0, so defining ``\lstinline$!=$'' and ``\lstinline$0$'' for user-defined types is enough to allow them to be used in logical expressions. 516 649 517 650 \item … … 522 655 \item 523 656 The ``address of'' operator. 524 It would seem useful to define a unary ``\lstinline @&@'' operator that returns values of some programmer-defined pointer-like type.657 It would seem useful to define a unary ``\lstinline$&$'' operator that returns values of some programmer-defined pointer-like type. 525 658 The problem lies with the type of the operator. 526 Consider the expression ``\lstinline @p = &x@'', where \lstinline@x@is of type527 \lstinline @T@ and \lstinline@p@ has the programmer-defined type \lstinline@T_ptr@.528 The expression might be treated as a call to the unary function ``\lstinline @&?@''.529 Now what is the type of the function's parameter? It can not be \lstinline @T@, because then \lstinline@x@would be passed by value, and there is no way to create a useful pointer-like result from a value.530 Hence the parameter must have type \lstinline @T *@.531 But then the expression must be rewritten as ``\lstinline @p = &?( &x )@''659 Consider the expression ``\lstinline$p = &x$'', where \lstinline$x$ is of type 660 \lstinline$T$ and \lstinline$p$ has the programmer-defined type \lstinline$T_ptr$. 661 The expression might be treated as a call to the unary function ``\lstinline$&?$''. 662 Now what is the type of the function's parameter? It can not be \lstinline$T$, because then \lstinline$x$ would be passed by value, and there is no way to create a useful pointer-like result from a value. 663 Hence the parameter must have type \lstinline$T *$. 664 But then the expression must be rewritten as ``\lstinline$p = &?( &x )$'' 532 665 ---which doesn't seem like progress! 533 666 534 667 The rule for address-of expressions would have to be something like ``keep applying address-of functions until you get one that takes a pointer argument, then use the built-in operator and stop''. 535 It seems simpler to define a conversion function from \lstinline @T *@ to \lstinline@T_ptr@.536 537 \item 538 The \lstinline @sizeof@operator.668 It seems simpler to define a conversion function from \lstinline$T *$ to \lstinline$T_ptr$. 669 670 \item 671 The \lstinline$sizeof$ operator. 539 672 It is already defined for every object type, and intimately tied into the language's storage allocation model. 540 673 Redefining it seems pointless. 541 674 542 675 \item 543 The ``member of'' operators ``\lstinline @.@'' and ``\lstinline@->@''.676 The ``member of'' operators ``\lstinline$.$'' and ``\lstinline$->$''. 544 677 These are not really infix operators, since their right ``operand'' is not a value or object. 545 678 … … 578 711 The ``fewest unsafe conversions'' rule ensures that the usual conversions are done, if possible. 579 712 The ``lowest total expression cost'' rule chooses the proper common type. 580 The odd-looking ``highest argument conversion cost'' rule ensures that, when unary expressions must be converted, conversions of function results are preferred to conversion of function arguments: \lstinline @(double)-i@ will be preferred to \lstinline@-(double)i@.713 The odd-looking ``highest argument conversion cost'' rule ensures that, when unary expressions must be converted, conversions of function results are preferred to conversion of function arguments: \lstinline$(double)-i$ will be preferred to \lstinline$-(double)i$. 581 714 582 715 The ``least polymorphic'' rule reduces the number of polymorphic function calls, since such functions are presumably more expensive than monomorphic functions and since the more specific function is presumably more appropriate. 583 716 It also gives preference to monomorphic values (such as the 584 \lstinline @int@ \lstinline@0@) over polymorphic values (such as the \Index{null pointer}585 \lstinline @0@\use{0}).717 \lstinline$int$ \lstinline$0$) over polymorphic values (such as the \Index{null pointer} 718 \lstinline$0$\use{0}). 586 719 However, interpretations that call polymorphic functions are preferred to interpretations that perform unsafe conversions, because those conversions potentially lose accuracy or violate strong typing. 587 720 588 721 There are two notable differences between \CFA's overload resolution rules and the rules for 589 {\CC} defined in \cite{ C++}.722 {\CC} defined in \cite{c++}. 590 723 First, the result type of a function plays a role. 591 724 In {\CC}, a function call must be completely resolved based on the arguments to the call in most circumstances. … … 603 736 \begin{rationale} 604 737 Predefined functions and constants have internal linkage because that simplifies optimization in traditional compile-and-link environments. 605 For instance, ``\lstinline @an_int + an_int@'' is equivalent to ``\lstinline@?+?(an_int, an_int)@''.738 For instance, ``\lstinline$an_int + an_int$'' is equivalent to ``\lstinline$?+?(an_int, an_int)$''. 606 739 If integer addition has not been redefined in the current scope, a compiler can generate code to perform the addition directly. 607 740 If predefined functions had external linkage, this optimization would be difficult. … … 629 762 \rhs \nonterm{constant} 630 763 \rhs \nonterm{string-literal} 631 \rhs \lstinline @(@ \nonterm{expression} \lstinline@)@764 \rhs \lstinline$($ \nonterm{expression} \lstinline$)$ 632 765 \rhs \nonterm{generic-selection} 633 766 \end{syntax} … … 635 768 \predefined 636 769 \begin{lstlisting} 637 const int 1; §\use{1}§638 const int 0; §\use{0}§770 const int 1;@\use{1}@ 771 const int 0;@\use{0}@ 639 772 forall( dtype DT ) DT * const 0; 640 773 forall( ftype FT ) FT * const 0; … … 645 778 646 779 A \nonterm{constant} or \nonterm{string-literal} has one valid interpretation, which has the type and value defined by {\c11}. 647 The predefined integer identifiers ``\lstinline @1@'' and ``\lstinline@0@'' have the integer values 1 and 0, respectively.648 The other two predefined ``\lstinline @0@'' identifiers are bound to polymorphic pointer values that, when specialized\index{specialization} with a data type or function type respectively, produce a null pointer of that type.780 The predefined integer identifiers ``\lstinline$1$'' and ``\lstinline$0$'' have the integer values 1 and 0, respectively. 781 The other two predefined ``\lstinline$0$'' identifiers are bound to polymorphic pointer values that, when specialized\index{specialization} with a data type or function type respectively, produce a null pointer of that type. 649 782 650 783 A parenthesised expression has the same interpretations as the contained \nonterm{expression}. 651 784 652 785 \examples 653 The expression \lstinline @(void *)0@\use{0} specializes the (polymorphic) null pointer to a null pointer to \lstinline@void@. \lstinline@(const void *)0@ does the same, and also uses a safe conversion from \lstinline@void *@ to \lstinline@const void *@.786 The expression \lstinline$(void *)0$\use{0} specializes the (polymorphic) null pointer to a null pointer to \lstinline$void$. \lstinline$(const void *)0$ does the same, and also uses a safe conversion from \lstinline$void *$ to \lstinline$const void *$. 654 787 In each case, the null pointer conversion is better\index{best valid interpretations} than the unsafe conversion of the integer 655 \lstinline @0@to a pointer.788 \lstinline$0$ to a pointer. 656 789 657 790 \begin{rationale} … … 659 792 660 793 \CFA does not have C's concept of ``null pointer constants'', which are not typed values but special strings of tokens. 661 The C token ``\lstinline @0@'' is an expression of type \lstinline@int@with the value ``zero'', and it \emph{also} is a null pointer constant.794 The C token ``\lstinline$0$'' is an expression of type \lstinline$int$ with the value ``zero'', and it \emph{also} is a null pointer constant. 662 795 Similarly, 663 ``\lstinline @(void *)0@ is an expression of type \lstinline@(void *)@whose value is a null pointer, and it also is a null pointer constant.664 However, in C, ``\lstinline @(void *)(void *)0@'' is796 ``\lstinline$(void *)0$ is an expression of type \lstinline$(void *)$ whose value is a null pointer, and it also is a null pointer constant. 797 However, in C, ``\lstinline$(void *)(void *)0$'' is 665 798 \emph{not} a null pointer constant, even though it is null-valued, a pointer, and constant! The semantics of C expressions contain many special cases to deal with subexpressions that are null pointer constants. 666 799 … … 669 802 \begin{lstlisting} 670 803 forall( dtype DT ) DT * const 0; 671 \end{lstlisting} means that \lstinline @0@is a polymorphic object, and contains a value that can have \emph{any} pointer-to-object type or pointer-to-incomplete type.804 \end{lstlisting} means that \lstinline$0$ is a polymorphic object, and contains a value that can have \emph{any} pointer-to-object type or pointer-to-incomplete type. 672 805 The only such value is the null pointer. 673 806 Therefore the type \emph{alone} is enough to identify a null pointer. … … 679 812 680 813 \constraints The best interpretation of the controlling expression shall be unambiguous\index{ambiguous interpretation}, and shall have type compatible with at most one of the types named in its generic association list. 681 If a generic selection has no \lstinline @default@generic association, the best interpretation of its controlling expression shall have type compatible with exactly one of the types named in its generic association list.814 If a generic selection has no \lstinline$default$ generic association, the best interpretation of its controlling expression shall have type compatible with exactly one of the types named in its generic association list. 682 815 683 816 \semantics … … 690 823 \lhs{postfix-expression} 691 824 \rhs \nonterm{primary-expression} 692 \rhs \nonterm{postfix-expression} \lstinline @[@ \nonterm{expression} \lstinline@]@693 \rhs \nonterm{postfix-expression} \lstinline @(@694 \nonterm{argument-expression-list}\opt \lstinline @)@695 \rhs \nonterm{postfix-expression} \lstinline @.@\nonterm{identifier}696 \rhs \nonterm{postfix-expression} \lstinline @->@\nonterm{identifier}697 \rhs \nonterm{postfix-expression} \lstinline @++@698 \rhs \nonterm{postfix-expression} \lstinline @--@699 \rhs \lstinline @(@ \nonterm{type-name} \lstinline@)@ \lstinline@{@ \nonterm{initializer-list} \lstinline@}@700 \rhs \lstinline @(@ \nonterm{type-name} \lstinline@)@ \lstinline@{@ \nonterm{initializer-list} \lstinline@,@ \lstinline@}@825 \rhs \nonterm{postfix-expression} \lstinline$[$ \nonterm{expression} \lstinline$]$ 826 \rhs \nonterm{postfix-expression} \lstinline$($ 827 \nonterm{argument-expression-list}\opt \lstinline$)$ 828 \rhs \nonterm{postfix-expression} \lstinline$.$ \nonterm{identifier} 829 \rhs \nonterm{postfix-expression} \lstinline$->$ \nonterm{identifier} 830 \rhs \nonterm{postfix-expression} \lstinline$++$ 831 \rhs \nonterm{postfix-expression} \lstinline$--$ 832 \rhs \lstinline$($ \nonterm{type-name} \lstinline$)$ \lstinline${$ \nonterm{initializer-list} \lstinline$}$ 833 \rhs \lstinline$($ \nonterm{type-name} \lstinline$)$ \lstinline${$ \nonterm{initializer-list} \lstinline$,$ \lstinline$}$ 701 834 \lhs{argument-expression-list} 702 835 \rhs \nonterm{assignment-expression} 703 \rhs \nonterm{argument-expression-list} \lstinline @,@836 \rhs \nonterm{argument-expression-list} \lstinline$,$ 704 837 \nonterm{assignment-expression} 705 838 \end{syntax} … … 707 840 \rewriterules 708 841 \begin{lstlisting} 709 a[b] §\rewrite§ ?[?]( b, a ) // if a has integer type§\use{?[?]}§710 a[b] §\rewrite§?[?]( a, b ) // otherwise711 a( §\emph{arguments}§ ) §\rewrite§ ?()( a, §\emph{arguments}§ )§\use{?()}§712 a++ §\rewrite§ ?++(&( a ))§\use{?++}§713 a-- §\rewrite§ ?--(&( a ))§\use{?--}§842 a[b] @\rewrite@ ?[?]( b, a ) // if a has integer type@\use{?[?]}@ 843 a[b] @\rewrite@ ?[?]( a, b ) // otherwise 844 a( @\emph{arguments}@ ) @\rewrite@ ?()( a, @\emph{arguments}@ )@\use{?()}@ 845 a++ @\rewrite@ ?++(&( a ))@\use{?++}@ 846 a-- @\rewrite@ ?--(&( a ))@\use{?--}@ 714 847 \end{lstlisting} 715 848 … … 719 852 \predefined 720 853 \begin{lstlisting} 721 forall( otype T ) lvalue T ?[?]( T *, ptrdiff_t ); §\use{ptrdiff_t}§854 forall( otype T ) lvalue T ?[?]( T *, ptrdiff_t );@\use{ptrdiff_t}@ 722 855 forall( otype T ) lvalue _Atomic T ?[?]( _Atomic T *, ptrdiff_t ); 723 856 forall( otype T ) lvalue const T ?[?]( const T *, ptrdiff_t ); … … 739 872 The interpretations of subscript expressions are the interpretations of the corresponding function call expressions. 740 873 \begin{rationale} 741 C defines subscripting as pointer arithmetic in a way that makes \lstinline @a[i]@and742 \lstinline @i[a]@ equivalent. \CFA provides the equivalence through a rewrite rule to reduce the number of overloadings of \lstinline@?[?]@.874 C defines subscripting as pointer arithmetic in a way that makes \lstinline$a[i]$ and 875 \lstinline$i[a]$ equivalent. \CFA provides the equivalence through a rewrite rule to reduce the number of overloadings of \lstinline$?[?]$. 743 876 744 877 Subscript expressions are rewritten as function calls that pass the first parameter by value. 745 878 This is somewhat unfortunate, since array-like types tend to be large. 746 The alternative is to use the rewrite rule ``\lstinline @a[b]@ \rewrite \lstinline@?[?](&(a), b)@''.747 However, C semantics forbid this approach: the \lstinline @a@ in ``\lstinline@a[b]@'' can be an arbitrary pointer value, which does not have an address.879 The alternative is to use the rewrite rule ``\lstinline$a[b]$ \rewrite \lstinline$?[?](&(a), b)$''. 880 However, C semantics forbid this approach: the \lstinline$a$ in ``\lstinline$a[b]$'' can be an arbitrary pointer value, which does not have an address. 748 881 749 882 The repetitive form of the predefined identifiers shows up a deficiency\index{deficiencies!pointers … … 760 893 \nonterm{postfix-expression} in a function call may have some interpretations that are function designators and some that are not. 761 894 762 For those interpretations of the \nonterm{postfix-expression} that are not function designators, the expression is rewritten and becomes a call of a function named ``\lstinline @?()@''.895 For those interpretations of the \nonterm{postfix-expression} that are not function designators, the expression is rewritten and becomes a call of a function named ``\lstinline$?()$''. 763 896 The valid interpretations of the rewritten expression are determined in the manner described below. 764 897 … … 768 901 \item if the argument corresponds to a parameter in the function designator's prototype, the argument interpretation must have the same type as the corresponding parameter, or be implicitly convertible to the parameter's type 769 902 \item if the function designator's type does not include a prototype or if the argument corresponds to 770 ``\lstinline @...@'' in a prototype, a \Index{default argument promotion} is applied to it.903 ``\lstinline$...$'' in a prototype, a \Index{default argument promotion} is applied to it. 771 904 \end{itemize} 772 905 The type of the valid interpretation is the return type of the function designator. … … 776 909 \begin{itemize} 777 910 \item 778 If the declaration of the implicit parameter uses \Index{type-class} \lstinline @type@\use{type}, the implicit argument must be an object type;779 if it uses \lstinline @dtype@, the implicit argument must be an object type or an incomplete type;780 and if it uses \lstinline @ftype@, the implicit argument must be a function type.911 If the declaration of the implicit parameter uses \Index{type-class} \lstinline$type$\use{type}, the implicit argument must be an object type; 912 if it uses \lstinline$dtype$, the implicit argument must be an object type or an incomplete type; 913 and if it uses \lstinline$ftype$, the implicit argument must be a function type. 781 914 782 915 \item if an explicit parameter's type uses any implicit parameters, then the corresponding explicit argument must have a type that is (or can be safely converted\index{safe conversion} to) the type produced by substituting the implicit arguments for the implicit parameters in the explicit parameter type. … … 797 930 \begin{rationale} 798 931 One desirable property of a polymorphic programming language is \define{generalizability}: the ability to replace an abstraction with a more general but equivalent abstraction without requiring changes in any of the uses of the original\cite{Cormack90}. 799 For instance, it should be possible to replace a function ``\lstinline @int f( int );@'' with ``\lstinline@forall( otype T ) T f( T );@'' without affecting any calls of \lstinline@f@.932 For instance, it should be possible to replace a function ``\lstinline$int f( int );$'' with ``\lstinline$forall( otype T ) T f( T );$'' without affecting any calls of \lstinline$f$. 800 933 801 934 \CFA\index{deficiencies!generalizability} does not fully possess this property, because … … 811 944 f = g( d, f ); // (3) (unsafe conversion to float) 812 945 \end{lstlisting} 813 If \lstinline @g@ was replaced by ``\lstinline@forall( otype T ) T g( T, T );@'', the first and second calls would be unaffected, but the third would change: \lstinline@f@would be converted to814 \lstinline @double@, and the result would be a \lstinline@double@.815 816 Another example is the function ``\lstinline @void h( int *);@''.946 If \lstinline$g$ was replaced by ``\lstinline$forall( otype T ) T g( T, T );$'', the first and second calls would be unaffected, but the third would change: \lstinline$f$ would be converted to 947 \lstinline$double$, and the result would be a \lstinline$double$. 948 949 Another example is the function ``\lstinline$void h( int *);$''. 817 950 This function can be passed a 818 \lstinline @void *@ argument, but the generalization ``\lstinline@forall( otype T ) void h( T *);@'' can not.819 In this case, \lstinline @void@ is not a valid value for \lstinline@T@because it is not an object type.820 If unsafe conversions were allowed, \lstinline @T@could be inferred to be \emph{any} object type, which is undesirable.951 \lstinline$void *$ argument, but the generalization ``\lstinline$forall( otype T ) void h( T *);$'' can not. 952 In this case, \lstinline$void$ is not a valid value for \lstinline$T$ because it is not an object type. 953 If unsafe conversions were allowed, \lstinline$T$ could be inferred to be \emph{any} object type, which is undesirable. 821 954 \end{rationale} 822 955 823 956 \examples 824 A function called ``\lstinline @?()@'' might be part of a numerical differentiation package.957 A function called ``\lstinline$?()$'' might be part of a numerical differentiation package. 825 958 \begin{lstlisting} 826 959 extern otype Derivative; … … 833 966 d = sin_dx( 12.9 ); 834 967 \end{lstlisting} 835 Here, the only interpretation of \lstinline @sin_dx@ is as an object of type \lstinline@Derivative@.836 For that interpretation, the function call is treated as ``\lstinline @?()( sin_dx, 12.9 )@''.968 Here, the only interpretation of \lstinline$sin_dx$ is as an object of type \lstinline$Derivative$. 969 For that interpretation, the function call is treated as ``\lstinline$?()( sin_dx, 12.9 )$''. 837 970 \begin{lstlisting} 838 971 int f( long ); // (1) … … 841 974 int i = f( 5 ); // calls (1) 842 975 \end{lstlisting} 843 Function (1) provides a valid interpretation of ``\lstinline @f( 5 )@'', using an implicit \lstinline@int@ to \lstinline@long@conversion.844 The other functions do not, since the second requires two arguments, and since there is no implicit conversion from \lstinline @int@ to \lstinline@int *@that could be used with the third function.976 Function (1) provides a valid interpretation of ``\lstinline$f( 5 )$'', using an implicit \lstinline$int$ to \lstinline$long$ conversion. 977 The other functions do not, since the second requires two arguments, and since there is no implicit conversion from \lstinline$int$ to \lstinline$int *$ that could be used with the third function. 845 978 846 979 \begin{lstlisting} … … 848 981 double d = h( 1.5 ); 849 982 \end{lstlisting} 850 ``\lstinline @1.5@'' is a \lstinline@double@ constant, so \lstinline@T@is inferred to be851 \lstinline @double@, and the result of the function call is a \lstinline@double@.983 ``\lstinline$1.5$'' is a \lstinline$double$ constant, so \lstinline$T$ is inferred to be 984 \lstinline$double$, and the result of the function call is a \lstinline$double$. 852 985 853 986 \begin{lstlisting} … … 864 997 g( i, p ); // calls (4) 865 998 \end{lstlisting} 866 The first call has valid interpretations for all four versions of \lstinline @g@. (6) and (7) are discarded because they involve unsafe \lstinline@double@-to-\lstinline@long@conversions. (5) is chosen because it is less polymorphic than (4).999 The first call has valid interpretations for all four versions of \lstinline$g$. (6) and (7) are discarded because they involve unsafe \lstinline$double$-to-\lstinline$long$ conversions. (5) is chosen because it is less polymorphic than (4). 867 1000 868 1001 For the second call, (7) is again discarded. 869 Of the remaining interpretations for (4), (5), and (6) (with \lstinline @i@ converted to \lstinline@long@), (6) is chosen because it is the least polymorphic.1002 Of the remaining interpretations for (4), (5), and (6) (with \lstinline$i$ converted to \lstinline$long$), (6) is chosen because it is the least polymorphic. 870 1003 871 1004 The third call has valid interpretations for all of the functions; … … 876 1009 forall( otype T ) T min( T, T ); 877 1010 double max( double, double ); 878 trait min_max( T ) { §\impl{min_max}§1011 trait min_max( T ) {@\impl{min_max}@ 879 1012 T min( T, T ); 880 1013 T max( T, T ); … … 883 1016 shuffle( 9, 10 ); 884 1017 \end{lstlisting} 885 The only possibility for \lstinline @U@ is \lstinline@double@, because that is the type used in the only visible \lstinline@max@ function. 9 and 10 must be converted to \lstinline@double@, and886 \lstinline @min@ must be specialized with \lstinline@T@ bound to \lstinline@double@.1018 The only possibility for \lstinline$U$ is \lstinline$double$, because that is the type used in the only visible \lstinline$max$ function. 9 and 10 must be converted to \lstinline$double$, and 1019 \lstinline$min$ must be specialized with \lstinline$T$ bound to \lstinline$double$. 887 1020 \begin{lstlisting} 888 1021 extern void q( int ); // (8) … … 892 1025 r( 0 ); 893 1026 \end{lstlisting} 894 The \lstinline @int 0@ could be passed to (8), or the \lstinline@(void *)@ \Index{specialization} of the null pointer\index{null pointer} \lstinline@0@\use{0} could be passed to (9).895 The former is chosen because the \lstinline @int@ \lstinline@0@is \Index{less polymorphic}.896 For the same reason, \lstinline @int@ \lstinline@0@ is passed to \lstinline@r()@, even though it has \emph{no} declared parameter types.1027 The \lstinline$int 0$ could be passed to (8), or the \lstinline$(void *)$ \Index{specialization} of the null pointer\index{null pointer} \lstinline$0$\use{0} could be passed to (9). 1028 The former is chosen because the \lstinline$int$ \lstinline$0$ is \Index{less polymorphic}. 1029 For the same reason, \lstinline$int$ \lstinline$0$ is passed to \lstinline$r()$, even though it has \emph{no} declared parameter types. 897 1030 898 1031 899 1032 \subsubsection{Structure and union members} 900 1033 901 \semantics In the member selection expression ``\lstinline @s@.\lstinline@m@'', there shall be at least one interpretation of \lstinline@s@ whose type is a structure type or union type containing a member named \lstinline@m@.902 If two or more interpretations of \lstinline @s@have members named903 \lstinline @m@with mutually compatible types, then the expression has an \Index{ambiguous interpretation} whose type is the composite type of the types of the members.904 If an interpretation of \lstinline @s@ has a member \lstinline@m@whose type is not compatible with any other905 \lstinline @s@'s \lstinline@m@, then the expression has an interpretation with the member's type.1034 \semantics In the member selection expression ``\lstinline$s$.\lstinline$m$'', there shall be at least one interpretation of \lstinline$s$ whose type is a structure type or union type containing a member named \lstinline$m$. 1035 If two or more interpretations of \lstinline$s$ have members named 1036 \lstinline$m$ with mutually compatible types, then the expression has an \Index{ambiguous interpretation} whose type is the composite type of the types of the members. 1037 If an interpretation of \lstinline$s$ has a member \lstinline$m$ whose type is not compatible with any other 1038 \lstinline$s$'s \lstinline$m$, then the expression has an interpretation with the member's type. 906 1039 The expression has no other interpretations. 907 1040 908 The expression ``\lstinline@p->m@'' has the same interpretations as the expression ``\lstinline@(*p).m@''. 1041 The expression ``\lstinline$p->m$'' has the same interpretations as the expression 1042 ``\lstinline$(*p).m$''. 909 1043 910 1044 … … 1001 1135 * ?--( _Atomic const restrict volatile T * _Atomic restrict volatile * ); 1002 1136 \end{lstlisting} 1003 For every extended integer type \lstinline @X@there exist1137 For every extended integer type \lstinline$X$ there exist 1004 1138 % Don't use predefined: keep this out of prelude.cf. 1005 1139 \begin{lstlisting} … … 1007 1141 ?--( volatile X * ), ?--( _Atomic volatile X * ); 1008 1142 \end{lstlisting} 1009 For every complete enumerated type \lstinline @E@there exist1143 For every complete enumerated type \lstinline$E$ there exist 1010 1144 % Don't use predefined: keep this out of prelude.cf. 1011 1145 \begin{lstlisting} … … 1015 1149 1016 1150 \begin{rationale} 1017 Note that ``\lstinline @++@'' and ``\lstinline@--@'' are rewritten as function calls that are given a pointer to that operand. (This is true of all operators that modify an operand.) As Hamish Macdonald has pointed out, this forces the modified operand of such expressions to be an lvalue.1151 Note that ``\lstinline$++$'' and ``\lstinline$--$'' are rewritten as function calls that are given a pointer to that operand. (This is true of all operators that modify an operand.) As Hamish Macdonald has pointed out, this forces the modified operand of such expressions to be an lvalue. 1018 1152 This partially enforces the C semantic rule that such operands must be \emph{modifiable} lvalues. 1019 1153 \end{rationale} … … 1021 1155 \begin{rationale} 1022 1156 In C, a semantic rule requires that pointer operands of increment and decrement be pointers to object types. 1023 Hence, \lstinline @void *@objects cannot be incremented.1024 In \CFA, the restriction follows from the use of a \lstinline @type@ parameter in the predefined function definitions, as opposed to \lstinline@dtype@, since only object types can be inferred arguments corresponding to the type parameter \lstinline@T@.1157 Hence, \lstinline$void *$ objects cannot be incremented. 1158 In \CFA, the restriction follows from the use of a \lstinline$type$ parameter in the predefined function definitions, as opposed to \lstinline$dtype$, since only object types can be inferred arguments corresponding to the type parameter \lstinline$T$. 1025 1159 \end{rationale} 1026 1160 1027 1161 \semantics 1028 1162 First, each interpretation of the operand of an increment or decrement expression is considered separately. 1029 For each interpretation that is a bit-field or is declared with the \Indexc{register}\index{storage-class specifier}, the expression has one valid interpretation, with the type of the operand, and the expression is ambiguous if the operand is. 1163 For each interpretation that is a bit-field or is declared with the 1164 \lstinline$register$\index{register@{\lstinline$register$}} \index{Itorage-class specifier}, the expression has one valid interpretation, with the type of the operand, and the expression is ambiguous if the operand is. 1030 1165 1031 1166 For the remaining interpretations, the expression is rewritten, and the interpretations of the expression are the interpretations of the corresponding function call. … … 1040 1175 \end{lstlisting} 1041 1176 \begin{sloppypar} 1042 Since \lstinline@&(vs)@ has type \lstinline@volatile short int *@, the best valid interpretation of 1043 \lstinline@vs++@ calls the \lstinline@?++@ function with the \lstinline@volatile short *@ parameter. 1044 \lstinline@s++@ does the same, applying the safe conversion from \lstinline@short int *@ to \lstinline@volatile short int *@. 1045 Note that there is no conversion that adds an \lstinline@_Atomic@ qualifier, so the \lstinline@_Atomic volatile short int@ overloading does not provide a valid interpretation. 1177 Since \lstinline$&(vs)$ has type \lstinline$volatile short int *$, the best valid interpretation of 1178 \lstinline$vs++$ calls the \lstinline$?++$ function with the \lstinline$volatile short *$ parameter. 1179 \lstinline$s++$ does the same, applying the safe conversion from \lstinline$short int *$ to 1180 \lstinline$volatile short int *$. 1181 Note that there is no conversion that adds an \lstinline$_Atomic$ qualifier, so the \lstinline$_Atomic volatile short int$ overloading does not provide a valid interpretation. 1046 1182 \end{sloppypar} 1047 1183 1048 There is no safe conversion from \lstinline @const short int *@ to \lstinline@volatile short int *@, and no \lstinline@?++@ function that accepts a \lstinline@const *@ parameter, so \lstinline@cs++@has no valid interpretations.1049 1050 The best valid interpretation of \lstinline @as++@ calls the \lstinline@short ?++@ function with the \lstinline@_Atomic volatile short int *@ parameter, applying a safe conversion to add the \lstinline@volatile@qualifier.1184 There is no safe conversion from \lstinline$const short int *$ to \lstinline$volatile short int *$, and no \lstinline$?++$ function that accepts a \lstinline$const *$ parameter, so \lstinline$cs++$ has no valid interpretations. 1185 1186 The best valid interpretation of \lstinline$as++$ calls the \lstinline$short ?++$ function with the \lstinline$_Atomic volatile short int *$ parameter, applying a safe conversion to add the \lstinline$volatile$ qualifier. 1051 1187 \begin{lstlisting} 1052 1188 char * const restrict volatile * restrict volatile pqpc; … … 1055 1191 ppc++; 1056 1192 \end{lstlisting} 1057 Since \lstinline @&(pqpc)@ has type \lstinline@char * const restrict volatile * restrict volatile *@, the best valid interpretation of \lstinline@pqpc++@ calls the polymorphic \lstinline@?++@ function with the \lstinline@const restrict volatile T * restrict volatile *@ parameter, inferring \lstinline@T@ to be \lstinline@char *@.1058 1059 \lstinline @ppc++@ calls the same function, again inferring \lstinline@T@ to be \lstinline@char *@, and using the safe conversions from \lstinline@T@ to \lstinline@T const@ \lstinline@restrict volatile@.1193 Since \lstinline$&(pqpc)$ has type \lstinline$char * const restrict volatile * restrict volatile *$, the best valid interpretation of \lstinline$pqpc++$ calls the polymorphic \lstinline$?++$ function with the \lstinline$const restrict volatile T * restrict volatile *$ parameter, inferring \lstinline$T$ to be \lstinline$char *$. 1194 1195 \lstinline$ppc++$ calls the same function, again inferring \lstinline$T$ to be \lstinline$char *$, and using the safe conversions from \lstinline$T$ to \lstinline$T const$ \lstinline$restrict volatile$. 1060 1196 1061 1197 \begin{rationale} … … 1071 1207 \begin{enumerate} 1072 1208 \item 1073 ``\lstinline @char * p; p++;@''.1074 The argument to \lstinline @?++@ has type \lstinline@char * *@, and the result has type \lstinline@char *@.1075 The expression would be valid if \lstinline @?++@were declared by1209 ``\lstinline$char * p; p++;$''. 1210 The argument to \lstinline$?++$ has type \lstinline$char * *$, and the result has type \lstinline$char *$. 1211 The expression would be valid if \lstinline$?++$ were declared by 1076 1212 \begin{lstlisting} 1077 1213 forall( otype T ) T * ?++( T * * ); 1078 \end{lstlisting} with \lstinline @T@ inferred to be \lstinline@char@.1079 1080 \item 1081 ``\lstinline @char *restrict volatile qp; qp++@''.1082 The result again has type \lstinline @char *@, but the argument now has type \lstinline@char *restrict volatile *@, so it cannot be passed to the hypothetical function declared in point 1.1214 \end{lstlisting} with \lstinline$T$ inferred to be \lstinline$char$. 1215 1216 \item 1217 ``\lstinline$char *restrict volatile qp; qp++$''. 1218 The result again has type \lstinline$char *$, but the argument now has type \lstinline$char *restrict volatile *$, so it cannot be passed to the hypothetical function declared in point 1. 1083 1219 Hence the actual predefined function is 1084 1220 \begin{lstlisting} 1085 1221 forall( otype T ) T * ?++( T * restrict volatile * ); 1086 \end{lstlisting} which also accepts a \lstinline @char * *@argument, because of the safe conversions that add1087 \lstinline @volatile@ and \lstinline@restrict@qualifiers. (The parameter is not const-qualified, so constant pointers cannot be incremented.)1088 1089 \item 1090 ``\lstinline @char *_Atomic ap; ap++@''.1091 The result again has type \lstinline @char *@, but no safe conversion adds an \lstinline@_Atomic@qualifier, so the function in point 2 is not applicable.1092 A separate overloading of \lstinline @?++@is required.1093 1094 \item 1095 ``\lstinline @char const volatile * pq; pq++@''.1222 \end{lstlisting} which also accepts a \lstinline$char * *$ argument, because of the safe conversions that add 1223 \lstinline$volatile$ and \lstinline$restrict$ qualifiers. (The parameter is not const-qualified, so constant pointers cannot be incremented.) 1224 1225 \item 1226 ``\lstinline$char *_Atomic ap; ap++$''. 1227 The result again has type \lstinline$char *$, but no safe conversion adds an \lstinline$_Atomic$ qualifier, so the function in point 2 is not applicable. 1228 A separate overloading of \lstinline$?++$ is required. 1229 1230 \item 1231 ``\lstinline$char const volatile * pq; pq++$''. 1096 1232 Here the result has type 1097 \lstinline @char const volatile *@, so a new overloading is needed:1233 \lstinline$char const volatile *$, so a new overloading is needed: 1098 1234 \begin{lstlisting} 1099 1235 forall( otype T ) T const volatile * ?++( T const volatile *restrict volatile * ); … … 1102 1238 1103 1239 \item 1104 ``\lstinline @float *restrict * prp; prp++@''.1105 The \lstinline @restrict@ qualifier is handled just like \lstinline@const@ and \lstinline@volatile@in the previous case:1240 ``\lstinline$float *restrict * prp; prp++$''. 1241 The \lstinline$restrict$ qualifier is handled just like \lstinline$const$ and \lstinline$volatile$ in the previous case: 1106 1242 \begin{lstlisting} 1107 1243 forall( otype T ) T restrict * ?++( T restrict *restrict volatile * ); 1108 \end{lstlisting} with \lstinline @T@ inferred to be \lstinline@float *@.1109 This looks odd, because {\c11} contains a constraint that requires restrict-qualified types to be pointer-to-object types, and \lstinline @T@is not syntactically a pointer type. \CFA loosens the constraint.1244 \end{lstlisting} with \lstinline$T$ inferred to be \lstinline$float *$. 1245 This looks odd, because {\c11} contains a constraint that requires restrict-qualified types to be pointer-to-object types, and \lstinline$T$ is not syntactically a pointer type. \CFA loosens the constraint. 1110 1246 \end{enumerate} 1111 1247 \end{rationale} … … 1123 1259 \lhs{unary-expression} 1124 1260 \rhs \nonterm{postfix-expression} 1125 \rhs \lstinline @++@\nonterm{unary-expression}1126 \rhs \lstinline @--@\nonterm{unary-expression}1261 \rhs \lstinline$++$ \nonterm{unary-expression} 1262 \rhs \lstinline$--$ \nonterm{unary-expression} 1127 1263 \rhs \nonterm{unary-operator} \nonterm{cast-expression} 1128 \rhs \lstinline @sizeof@\nonterm{unary-expression}1129 \rhs \lstinline @sizeof@ \lstinline@(@ \nonterm{type-name} \lstinline@)@1130 \lhs{unary-operator} one of \rhs \lstinline @&@ \lstinline@*@ \lstinline@+@ \lstinline@-@ \lstinline@~@ \lstinline@!@1264 \rhs \lstinline$sizeof$ \nonterm{unary-expression} 1265 \rhs \lstinline$sizeof$ \lstinline$($ \nonterm{type-name} \lstinline$)$ 1266 \lhs{unary-operator} one of \rhs \lstinline$&$ \lstinline$*$ \lstinline$+$ \lstinline$-$ \lstinline$~$ \lstinline$!$ 1131 1267 \end{syntax} 1132 1268 1133 1269 \rewriterules 1134 1270 \begin{lstlisting} 1135 *a §\rewrite§ *?( a ) §\use{*?}§1136 +a §\rewrite§ +?( a ) §\use{+?}§1137 -a §\rewrite§ -?( a ) §\use{-?}§1138 ~a §\rewrite§ ~?( a ) §\use{~?}§1139 !a §\rewrite§ !?( a ) §\use{"!?}§1140 ++a §\rewrite§ ++?(&( a )) §\use{++?}§1141 --a §\rewrite§ --?(&( a )) §\use{--?}§1271 *a @\rewrite@ *?( a ) @\use{*?}@ 1272 +a @\rewrite@ +?( a ) @\use{+?}@ 1273 -a @\rewrite@ -?( a ) @\use{-?}@ 1274 ~a @\rewrite@ ~?( a ) @\use{~?}@ 1275 !a @\rewrite@ !?( a ) @\use{"!?}@ 1276 ++a @\rewrite@ ++?(&( a )) @\use{++?}@ 1277 --a @\rewrite@ --?(&( a )) @\use{--?}@ 1142 1278 \end{lstlisting} 1143 1279 … … 1235 1371 * --?( _Atomic const restrict volatile T * _Atomic restrict volatile * ); 1236 1372 \end{lstlisting} 1237 For every extended integer type \lstinline @X@there exist1373 For every extended integer type \lstinline$X$ there exist 1238 1374 % Don't use predefined: keep this out of prelude.cf. 1239 1375 \begin{lstlisting} … … 1243 1379 --?( _Atomic volatile X * ); 1244 1380 \end{lstlisting} 1245 For every complete enumerated type \lstinline @E@there exist1381 For every complete enumerated type \lstinline$E$ there exist 1246 1382 % Don't use predefined: keep this out of prelude.cf. 1247 1383 \begin{lstlisting} … … 1280 1416 1281 1417 \constraints 1282 The operand of the unary ``\lstinline @&@'' operator shall have exactly one1418 The operand of the unary ``\lstinline$&$'' operator shall have exactly one 1283 1419 \Index{interpretation}\index{ambiguous interpretation}, which shall be unambiguous. 1284 1420 1285 1421 \semantics 1286 The ``\lstinline @&@'' expression has one interpretation which is of type \lstinline@T *@, where1287 \lstinline @T@is the type of the operand.1422 The ``\lstinline$&$'' expression has one interpretation which is of type \lstinline$T *$, where 1423 \lstinline$T$ is the type of the operand. 1288 1424 1289 1425 The interpretations of an indirection expression are the interpretations of the corresponding function call. … … 1314 1450 forall( ftype FT ) int !?( FT * ); 1315 1451 \end{lstlisting} 1316 For every extended integer type \lstinline @X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@there exist1452 For every extended integer type \lstinline$X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$ there exist 1317 1453 % Don't use predefined: keep this out of prelude.cf. 1318 1454 \begin{lstlisting} … … 1327 1463 \begin{lstlisting} 1328 1464 long int li; 1329 void eat_double( double ); §\use{eat_double}§1330 eat_double(-li ); // §\rewrite§eat_double( -?( li ) );1331 \end{lstlisting} 1332 The valid interpretations of ``\lstinline @-li@'' (assuming no extended integer types exist) are1465 void eat_double( double );@\use{eat_double}@ 1466 eat_double(-li ); // @\rewrite@ eat_double( -?( li ) ); 1467 \end{lstlisting} 1468 The valid interpretations of ``\lstinline$-li$'' (assuming no extended integer types exist) are 1333 1469 \begin{center} 1334 1470 \begin{tabular}{llc} interpretation & result type & expression conversion cost \\ 1335 1471 \hline 1336 \lstinline @-?( (int)li )@ & \lstinline@int@& (unsafe) \\1337 \lstinline @-?( (unsigned)li)@ & \lstinline@unsigned int@& (unsafe) \\1338 \lstinline @-?( (long)li)@ & \lstinline@long@& 0 \\1339 \lstinline @-?( (long unsigned int)li)@ & \lstinline@long unsigned int@& 1 \\1340 \lstinline @-?( (long long int)li)@ & \lstinline@long long int@& 2 \\1341 \lstinline @-?( (long long unsigned int)li)@ & \lstinline@long long unsigned int@& 3 \\1342 \lstinline @-?( (float)li)@ & \lstinline@float@& 4 \\1343 \lstinline @-?( (double)li)@ & \lstinline@double@& 5 \\1344 \lstinline @-?( (long double)li)@ & \lstinline@long double@& 6 \\1345 \lstinline @-?( (_Complex float)li)@ & \lstinline@float@& (unsafe) \\1346 \lstinline @-?( (_Complex double)li)@ & \lstinline@double@& (unsafe) \\1347 \lstinline @-?( (_Complex long double)li)@ & \lstinline@long double@& (unsafe) \\1472 \lstinline$-?( (int)li )$ & \lstinline$int$ & (unsafe) \\ 1473 \lstinline$-?( (unsigned)li)$ & \lstinline$unsigned int$ & (unsafe) \\ 1474 \lstinline$-?( (long)li)$ & \lstinline$long$ & 0 \\ 1475 \lstinline$-?( (long unsigned int)li)$ & \lstinline$long unsigned int$ & 1 \\ 1476 \lstinline$-?( (long long int)li)$ & \lstinline$long long int$ & 2 \\ 1477 \lstinline$-?( (long long unsigned int)li)$ & \lstinline$long long unsigned int$& 3 \\ 1478 \lstinline$-?( (float)li)$ & \lstinline$float$ & 4 \\ 1479 \lstinline$-?( (double)li)$ & \lstinline$double$ & 5 \\ 1480 \lstinline$-?( (long double)li)$ & \lstinline$long double$ & 6 \\ 1481 \lstinline$-?( (_Complex float)li)$ & \lstinline$float$ & (unsafe) \\ 1482 \lstinline$-?( (_Complex double)li)$ & \lstinline$double$ & (unsafe) \\ 1483 \lstinline$-?( (_Complex long double)li)$ & \lstinline$long double$ & (unsafe) \\ 1348 1484 \end{tabular} 1349 1485 \end{center} 1350 The valid interpretations of the \lstinline @eat_double@call, with the cost of the argument conversion and the cost of the entire expression, are1486 The valid interpretations of the \lstinline$eat_double$ call, with the cost of the argument conversion and the cost of the entire expression, are 1351 1487 \begin{center} 1352 1488 \begin{tabular}{lcc} interpretation & argument cost & expression cost \\ 1353 1489 \hline 1354 \lstinline @eat_double( (double)-?( (int)li) )@& 7 & (unsafe) \\1355 \lstinline @eat_double( (double)-?( (unsigned)li) )@& 6 & (unsafe) \\1356 \lstinline @eat_double( (double)-?(li) )@& 5 & \(0+5=5\) \\1357 \lstinline @eat_double( (double)-?( (long unsigned int)li) )@& 4 & \(1+4=5\) \\1358 \lstinline @eat_double( (double)-?( (long long int)li) )@& 3 & \(2+3=5\) \\1359 \lstinline @eat_double( (double)-?( (long long unsigned int)li) )@& 2 & \(3+2=5\) \\1360 \lstinline @eat_double( (double)-?( (float)li) )@& 1 & \(4+1=5\) \\1361 \lstinline @eat_double( (double)-?( (double)li) )@& 0 & \(5+0=5\) \\1362 \lstinline @eat_double( (double)-?( (long double)li) )@& (unsafe) & (unsafe) \\1363 \lstinline @eat_double( (double)-?( (_Complex float)li) )@& (unsafe) & (unsafe) \\1364 \lstinline @eat_double( (double)-?( (_Complex double)li) )@& (unsafe) & (unsafe) \\1365 \lstinline @eat_double( (double)-?( (_Complex long double)li) )@& (unsafe) & (unsafe) \\1490 \lstinline$eat_double( (double)-?( (int)li) )$ & 7 & (unsafe) \\ 1491 \lstinline$eat_double( (double)-?( (unsigned)li) )$ & 6 & (unsafe) \\ 1492 \lstinline$eat_double( (double)-?(li) )$ & 5 & \(0+5=5\) \\ 1493 \lstinline$eat_double( (double)-?( (long unsigned int)li) )$ & 4 & \(1+4=5\) \\ 1494 \lstinline$eat_double( (double)-?( (long long int)li) )$ & 3 & \(2+3=5\) \\ 1495 \lstinline$eat_double( (double)-?( (long long unsigned int)li) )$& 2 & \(3+2=5\) \\ 1496 \lstinline$eat_double( (double)-?( (float)li) )$ & 1 & \(4+1=5\) \\ 1497 \lstinline$eat_double( (double)-?( (double)li) )$ & 0 & \(5+0=5\) \\ 1498 \lstinline$eat_double( (double)-?( (long double)li) )$ & (unsafe) & (unsafe) \\ 1499 \lstinline$eat_double( (double)-?( (_Complex float)li) )$ & (unsafe) & (unsafe) \\ 1500 \lstinline$eat_double( (double)-?( (_Complex double)li) )$ & (unsafe) & (unsafe) \\ 1501 \lstinline$eat_double( (double)-?( (_Complex long double)li) )$ & (unsafe) & (unsafe) \\ 1366 1502 \end{tabular} 1367 1503 \end{center} 1368 Each has result type \lstinline @void@, so the best must be selected.1504 Each has result type \lstinline$void$, so the best must be selected. 1369 1505 The interpretations involving unsafe conversions are discarded. 1370 1506 The remainder have equal expression conversion costs, so the 1371 1507 ``highest argument conversion cost'' rule is invoked, and the chosen interpretation is 1372 \lstinline @eat_double( (double)-?(li) )@.1373 1374 1375 \subsubsection [The sizeof and \_Alignof operators]{The \lstinline@sizeof@ and \lstinline@_Alignof@operators}1508 \lstinline$eat_double( (double)-?(li) )$. 1509 1510 1511 \subsubsection{The \lstinline$sizeof$ and \lstinline$_Alignof$ operators} 1376 1512 1377 1513 \constraints 1378 The operand of \lstinline@sizeof@ or \lstinline@_Alignof@ shall not be \lstinline@type@, \lstinline@dtype@, or \lstinline@ftype@. 1379 1380 When the \lstinline@sizeof@\use{sizeof} operator is applied to an expression, the expression shall have exactly one \Index{interpretation}\index{ambiguous interpretation}, which shall be unambiguous. \semantics A \lstinline@sizeof@ or \lstinline@_Alignof@ expression has one interpretation, of type \lstinline@size_t@. 1381 1382 When \lstinline@sizeof@ is applied to an identifier declared by a \nonterm{type-declaration} or a 1514 The operand of \lstinline$sizeof$ or \lstinline$_Alignof$ shall not be \lstinline$type$, 1515 \lstinline$dtype$, or \lstinline$ftype$. 1516 1517 When the \lstinline$sizeof$\use{sizeof} operator is applied to an expression, the expression shall have exactly one \Index{interpretation}\index{ambiguous interpretation}, which shall be unambiguous. \semantics A \lstinline$sizeof$ or \lstinline$_Alignof$ expression has one interpretation, of type \lstinline$size_t$. 1518 1519 When \lstinline$sizeof$ is applied to an identifier declared by a \nonterm{type-declaration} or a 1383 1520 \nonterm{type-parameter}, it yields the size in bytes of the type that implements the operand. 1384 1521 When the operand is an opaque type or an inferred type parameter\index{inferred parameter}, the expression is not a constant expression. 1385 1522 1386 When \lstinline @_Alignof@is applied to an identifier declared by a \nonterm{type-declaration} or a1523 When \lstinline$_Alignof$ is applied to an identifier declared by a \nonterm{type-declaration} or a 1387 1524 \nonterm{type-parameter}, it yields the alignment requirement of the type that implements the operand. 1388 1525 When the operand is an opaque type or an inferred type parameter\index{inferred parameter}, the expression is not a constant expression. … … 1391 1528 otype Pair = struct { int first, second; }; 1392 1529 size_t p_size = sizeof(Pair); // constant expression 1393 extern otype Rational; §\use{Rational}§1530 extern otype Rational;@\use{Rational}@ 1394 1531 size_t c_size = sizeof(Rational); // non-constant expression 1395 1532 forall(type T) T f(T p1, T p2) { … … 1398 1535 } 1399 1536 \end{lstlisting} 1400 ``\lstinline @sizeof Rational@'', although not statically known, is fixed.1401 Within \lstinline @f()@,1402 ``\lstinline @sizeof(T)@'' is fixed for each call of \lstinline@f()@, but may vary from call to call.1537 ``\lstinline$sizeof Rational$'', although not statically known, is fixed. 1538 Within \lstinline$f()$, 1539 ``\lstinline$sizeof(T)$'' is fixed for each call of \lstinline$f()$, but may vary from call to call. 1403 1540 \end{rationale} 1404 1541 … … 1409 1546 \lhs{cast-expression} 1410 1547 \rhs \nonterm{unary-expression} 1411 \rhs \lstinline @(@ \nonterm{type-name} \lstinline@)@\nonterm{cast-expression}1548 \rhs \lstinline$($ \nonterm{type-name} \lstinline$)$ \nonterm{cast-expression} 1412 1549 \end{syntax} 1413 1550 1414 1551 \constraints 1415 The \nonterm{type-name} in a \nonterm{cast-expression} shall not be \lstinline @type@,1416 \lstinline @dtype@, or \lstinline@ftype@.1552 The \nonterm{type-name} in a \nonterm{cast-expression} shall not be \lstinline$type$, 1553 \lstinline$dtype$, or \lstinline$ftype$. 1417 1554 1418 1555 \semantics 1419 1556 1420 In a \Index{cast expression} ``\lstinline @(@\nonterm{type-name}\lstinline@)e@'', if1421 \nonterm{type-name} is the type of an interpretation of \lstinline @e@, then that interpretation is the only interpretation of the cast expression;1422 otherwise, \lstinline @e@shall have some interpretation that can be converted to \nonterm{type-name}, and the interpretation of the cast expression is the cast of the interpretation that can be converted at the lowest cost.1557 In a \Index{cast expression} ``\lstinline$($\nonterm{type-name}\lstinline$)e$'', if 1558 \nonterm{type-name} is the type of an interpretation of \lstinline$e$, then that interpretation is the only interpretation of the cast expression; 1559 otherwise, \lstinline$e$ shall have some interpretation that can be converted to \nonterm{type-name}, and the interpretation of the cast expression is the cast of the interpretation that can be converted at the lowest cost. 1423 1560 The cast expression's interpretation is ambiguous\index{ambiguous interpretation} if more than one interpretation can be converted at the lowest cost or if the selected interpretation is ambiguous. 1424 1561 … … 1433 1570 \lhs{multiplicative-expression} 1434 1571 \rhs \nonterm{cast-expression} 1435 \rhs \nonterm{multiplicative-expression} \lstinline @*@\nonterm{cast-expression}1436 \rhs \nonterm{multiplicative-expression} \lstinline @/@\nonterm{cast-expression}1437 \rhs \nonterm{multiplicative-expression} \lstinline @%@\nonterm{cast-expression}1572 \rhs \nonterm{multiplicative-expression} \lstinline$*$ \nonterm{cast-expression} 1573 \rhs \nonterm{multiplicative-expression} \lstinline$/$ \nonterm{cast-expression} 1574 \rhs \nonterm{multiplicative-expression} \lstinline$%$ \nonterm{cast-expression} 1438 1575 \end{syntax} 1439 1576 1440 1577 \rewriterules 1441 1578 \begin{lstlisting} 1442 a * b §\rewrite§ ?*?( a, b )§\use{?*?}§1443 a / b §\rewrite§ ?/?( a, b )§\use{?/?}§1444 a % b §\rewrite§ ?%?( a, b )§\use{?%?}§1579 a * b @\rewrite@ ?*?( a, b )@\use{?*?}@ 1580 a / b @\rewrite@ ?/?( a, b )@\use{?/?}@ 1581 a % b @\rewrite@ ?%?( a, b )@\use{?%?}@ 1445 1582 \end{lstlisting} 1446 1583 … … 1469 1606 ?*?( _Complex long double, _Complex long double ), ?/?( _Complex long double, _Complex long double ); 1470 1607 \end{lstlisting} 1471 For every extended integer type \lstinline @X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@there exist1608 For every extended integer type \lstinline$X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$ there exist 1472 1609 % Don't use predefined: keep this out of prelude.cf. 1473 1610 \begin{lstlisting} … … 1487 1624 int i; 1488 1625 long li; 1489 void eat_double( double ); §\use{eat_double}§1626 void eat_double( double );@\use{eat_double}@ 1490 1627 eat_double( li % i ); 1491 1628 \end{lstlisting} 1492 ``\lstinline @li % i@'' is rewritten as ``\lstinline@?%?(li, i )@''.1493 The valid interpretations of \lstinline @?%?(li, i )@, the cost\index{conversion cost} of converting their arguments, and the cost of converting the result to \lstinline@double@(assuming no extended integer types are present ) are1629 ``\lstinline$li % i$'' is rewritten as ``\lstinline$?%?(li, i )$''. 1630 The valid interpretations of \lstinline$?%?(li, i )$, the cost\index{conversion cost} of converting their arguments, and the cost of converting the result to \lstinline$double$ (assuming no extended integer types are present ) are 1494 1631 \begin{center} 1495 1632 \begin{tabular}{lcc} interpretation & argument cost & result cost \\ 1496 1633 \hline 1497 \lstinline @ ?%?( (int)li, i )@& (unsafe) & 6 \\1498 \lstinline @ ?%?( (unsigned)li,(unsigned)i )@& (unsafe) & 5 \\1499 \lstinline @ ?%?( li, (long)i )@& 1 & 4 \\1500 \lstinline @ ?%?( (long unsigned)li,(long unsigned)i )@& 3 & 3 \\1501 \lstinline @ ?%?( (long long)li,(long long)i )@& 5 & 2 \\1502 \lstinline @ ?%?( (long long unsigned)li, (long long unsigned)i )@& 7 & 1 \\1634 \lstinline$ ?%?( (int)li, i )$ & (unsafe) & 6 \\ 1635 \lstinline$ ?%?( (unsigned)li,(unsigned)i )$ & (unsafe) & 5 \\ 1636 \lstinline$ ?%?( li, (long)i )$ & 1 & 4 \\ 1637 \lstinline$ ?%?( (long unsigned)li,(long unsigned)i )$ & 3 & 3 \\ 1638 \lstinline$ ?%?( (long long)li,(long long)i )$ & 5 & 2 \\ 1639 \lstinline$ ?%?( (long long unsigned)li, (long long unsigned)i )$ & 7 & 1 \\ 1503 1640 \end{tabular} 1504 1641 \end{center} 1505 The best interpretation of \lstinline @eat_double( li, i )@is1506 \lstinline @eat_double( (double)?%?(li, (long)i ))@, which has no unsafe conversions and the lowest total cost.1507 1508 \begin{rationale} 1509 {\c11} defines most arithmetic operations to apply an \Index{integer promotion} to any argument that belongs to a type that has an \Index{integer conversion rank} less than that of \lstinline @int@.If1510 \lstinline @s@ is a \lstinline@short int@, ``\lstinline@s *s@'' does not have type \lstinline@short int@;1511 it is treated as ``\lstinline @( (int)s ) * ( (int)s )@'', and has type \lstinline@int@. \CFA matches that pattern;1512 it does not predefine ``\lstinline @short ?*?( short, short )@''.1642 The best interpretation of \lstinline$eat_double( li, i )$ is 1643 \lstinline$eat_double( (double)?%?(li, (long)i ))$, which has no unsafe conversions and the lowest total cost. 1644 1645 \begin{rationale} 1646 {\c11} defines most arithmetic operations to apply an \Index{integer promotion} to any argument that belongs to a type that has an \Index{integer conversion rank} less than that of \lstinline$int$.If 1647 \lstinline$s$ is a \lstinline$short int$, ``\lstinline$s *s$'' does not have type \lstinline$short int$; 1648 it is treated as ``\lstinline$( (int)s ) * ( (int)s )$'', and has type \lstinline$int$. \CFA matches that pattern; 1649 it does not predefine ``\lstinline$short ?*?( short, short )$''. 1513 1650 1514 1651 These ``missing'' operators limit polymorphism. … … 1519 1656 square( s ); 1520 1657 \end{lstlisting} 1521 Since \CFA does not define a multiplication operator for \lstinline @short int@,1522 \lstinline @square( s )@ is treated as \lstinline@square( (int)s )@, and the result has type1523 \lstinline @int@.1658 Since \CFA does not define a multiplication operator for \lstinline$short int$, 1659 \lstinline$square( s )$ is treated as \lstinline$square( (int)s )$, and the result has type 1660 \lstinline$int$. 1524 1661 This is mildly surprising, but it follows the {\c11} operator pattern. 1525 1662 … … 1531 1668 \end{lstlisting} 1532 1669 This has no valid interpretations, because \CFA has no conversion from ``array of 1533 \lstinline @short int@'' to ``array of \lstinline@int@''.1670 \lstinline$short int$'' to ``array of \lstinline$int$''. 1534 1671 The alternatives in such situations include 1535 1672 \begin{itemize} 1536 1673 \item 1537 Defining monomorphic overloadings of \lstinline @product@ for \lstinline@short@and the other1674 Defining monomorphic overloadings of \lstinline$product$ for \lstinline$short$ and the other 1538 1675 ``small'' types. 1539 1676 \item 1540 Defining ``\lstinline @short ?*?( short, short )@'' within the scope containing the call to1541 \lstinline @product@.1542 \item 1543 Defining \lstinline @product@to take as an argument a conversion function from the ``small'' type to the operator's argument type.1677 Defining ``\lstinline$short ?*?( short, short )$'' within the scope containing the call to 1678 \lstinline$product$. 1679 \item 1680 Defining \lstinline$product$ to take as an argument a conversion function from the ``small'' type to the operator's argument type. 1544 1681 \end{itemize} 1545 1682 \end{rationale} … … 1551 1688 \lhs{additive-expression} 1552 1689 \rhs \nonterm{multiplicative-expression} 1553 \rhs \nonterm{additive-expression} \lstinline @+@\nonterm{multiplicative-expression}1554 \rhs \nonterm{additive-expression} \lstinline @-@\nonterm{multiplicative-expression}1690 \rhs \nonterm{additive-expression} \lstinline$+$ \nonterm{multiplicative-expression} 1691 \rhs \nonterm{additive-expression} \lstinline$-$ \nonterm{multiplicative-expression} 1555 1692 \end{syntax} 1556 1693 1557 1694 \rewriterules 1558 1695 \begin{lstlisting} 1559 a + b §\rewrite§ ?+?( a, b )§\use{?+?}§1560 a - b §\rewrite§ ?-?( a, b )§\use{?-?}§1696 a + b @\rewrite@ ?+?( a, b )@\use{?+?}@ 1697 a - b @\rewrite@ ?-?( a, b )@\use{?-?}@ 1561 1698 \end{lstlisting} 1562 1699 … … 1611 1748 * ?-?( _Atomic const restrict volatile T *, _Atomic const restrict volatile T * ); 1612 1749 \end{lstlisting} 1613 For every extended integer type \lstinline @X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@there exist1750 For every extended integer type \lstinline$X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$ there exist 1614 1751 % Don't use predefined: keep this out of prelude.cf. 1615 1752 \begin{lstlisting} … … 1621 1758 1622 1759 \begin{rationale} 1623 \lstinline @ptrdiff_t@ is an implementation-defined identifier defined in \lstinline@<stddef.h>@that is synonymous with a signed integral type that is large enough to hold the difference between two pointers.1760 \lstinline$ptrdiff_t$ is an implementation-defined identifier defined in \lstinline$<stddef.h>$ that is synonymous with a signed integral type that is large enough to hold the difference between two pointers. 1624 1761 It seems reasonable to use it for pointer addition as well. (This is technically a difference between \CFA and C, which only specifies that pointer addition uses an \emph{integral} argument.) Hence it is also used for subscripting, which is defined in terms of pointer addition. 1625 The {\c11} standard uses \lstinline @size_t@ in several cases where a library function takes an argument that is used as a subscript, but \lstinline@size_t@is unsuitable here because it is an unsigned type.1762 The {\c11} standard uses \lstinline$size_t$ in several cases where a library function takes an argument that is used as a subscript, but \lstinline$size_t$ is unsuitable here because it is an unsigned type. 1626 1763 \end{rationale} 1627 1764 … … 1632 1769 \lhs{shift-expression} 1633 1770 \rhs \nonterm{additive-expression} 1634 \rhs \nonterm{shift-expression} \lstinline @<<@\nonterm{additive-expression}1635 \rhs \nonterm{shift-expression} \lstinline @>>@\nonterm{additive-expression}1771 \rhs \nonterm{shift-expression} \lstinline$<<$ \nonterm{additive-expression} 1772 \rhs \nonterm{shift-expression} \lstinline$>>$ \nonterm{additive-expression} 1636 1773 \end{syntax} 1637 1774 1638 1775 \rewriterules \use{?>>?}%use{?<<?} 1639 1776 \begin{lstlisting} 1640 a << b §\rewrite§?<<?( a, b )1641 a >> b §\rewrite§?>>?( a, b )1777 a << b @\rewrite@ ?<<?( a, b ) 1778 a >> b @\rewrite@ ?>>?( a, b ) 1642 1779 \end{lstlisting} 1643 1780 … … 1651 1788 long long unsigned int ?<<?( long long unsigned int, int ), ?>>?( long long unsigned int, int); 1652 1789 \end{lstlisting} 1653 For every extended integer type \lstinline @X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@there exist1790 For every extended integer type \lstinline$X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$ there exist 1654 1791 % Don't use predefined: keep this out of prelude.cf. 1655 1792 \begin{lstlisting} … … 1671 1808 \lhs{relational-expression} 1672 1809 \rhs \nonterm{shift-expression} 1673 \rhs \nonterm{relational-expression} \lstinline @< @\nonterm{shift-expression}1674 \rhs \nonterm{relational-expression} \lstinline @> @\nonterm{shift-expression}1675 \rhs \nonterm{relational-expression} \lstinline @<=@\nonterm{shift-expression}1676 \rhs \nonterm{relational-expression} \lstinline @>=@\nonterm{shift-expression}1810 \rhs \nonterm{relational-expression} \lstinline$< $ \nonterm{shift-expression} 1811 \rhs \nonterm{relational-expression} \lstinline$> $ \nonterm{shift-expression} 1812 \rhs \nonterm{relational-expression} \lstinline$<=$ \nonterm{shift-expression} 1813 \rhs \nonterm{relational-expression} \lstinline$>=$ \nonterm{shift-expression} 1677 1814 \end{syntax} 1678 1815 1679 1816 \rewriterules\use{?>?}\use{?>=?}%use{?<?}%use{?<=?} 1680 1817 \begin{lstlisting} 1681 a < b §\rewrite§?<?( a, b )1682 a > b §\rewrite§?>?( a, b )1683 a <= b §\rewrite§?<=?( a, b )1684 a >= b §\rewrite§?>=?( a, b )1818 a < b @\rewrite@ ?<?( a, b ) 1819 a > b @\rewrite@ ?>?( a, b ) 1820 a <= b @\rewrite@ ?<=?( a, b ) 1821 a >= b @\rewrite@ ?>=?( a, b ) 1685 1822 \end{lstlisting} 1686 1823 … … 1714 1851 ?>=?( _Atomic const restrict volatile DT *, _Atomic const restrict volatile DT * ); 1715 1852 \end{lstlisting} 1716 For every extended integer type \lstinline @X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@there exist1853 For every extended integer type \lstinline$X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$ there exist 1717 1854 % Don't use predefined: keep this out of prelude.cf. 1718 1855 \begin{lstlisting} … … 1732 1869 \lhs{equality-expression} 1733 1870 \rhs \nonterm{relational-expression} 1734 \rhs \nonterm{equality-expression} \lstinline @==@\nonterm{relational-expression}1735 \rhs \nonterm{equality-expression} \lstinline @!=@\nonterm{relational-expression}1871 \rhs \nonterm{equality-expression} \lstinline$==$ \nonterm{relational-expression} 1872 \rhs \nonterm{equality-expression} \lstinline$!=$ \nonterm{relational-expression} 1736 1873 \end{syntax} 1737 1874 1738 1875 \rewriterules 1739 1876 \begin{lstlisting} 1740 a == b §\rewrite§ ?==?( a, b )§\use{?==?}§1741 a != b §\rewrite§ ?!=?( a, b )§\use{?"!=?}§1877 a == b @\rewrite@ ?==?( a, b )@\use{?==?}@ 1878 a != b @\rewrite@ ?!=?( a, b )@\use{?"!=?}@ 1742 1879 \end{lstlisting} 1743 1880 … … 1792 1929 ?==?( forall( ftype FT2) FT2*, forall( ftype FT3) FT3 * ), ?!=?( forall( ftype FT2) FT2*, forall( ftype FT3) FT3 * ); 1793 1930 \end{lstlisting} 1794 For every extended integer type \lstinline @X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@there exist1931 For every extended integer type \lstinline$X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$ there exist 1795 1932 % Don't use predefined: keep this out of prelude.cf. 1796 1933 \begin{lstlisting} … … 1800 1937 1801 1938 \begin{rationale} 1802 The polymorphic equality operations come in three styles: comparisons between pointers of compatible types, between pointers to \lstinline @void@and pointers to object types or incomplete types, and between the \Index{null pointer} constant and pointers to any type.1939 The polymorphic equality operations come in three styles: comparisons between pointers of compatible types, between pointers to \lstinline$void$ and pointers to object types or incomplete types, and between the \Index{null pointer} constant and pointers to any type. 1803 1940 In the last case, a special constraint rule for null pointer constant operands has been replaced by a consequence of the \CFA type system. 1804 1941 \end{rationale} … … 1821 1958 \lhs{AND-expression} 1822 1959 \rhs \nonterm{equality-expression} 1823 \rhs \nonterm{AND-expression} \lstinline @&@\nonterm{equality-expression}1960 \rhs \nonterm{AND-expression} \lstinline$&$ \nonterm{equality-expression} 1824 1961 \end{syntax} 1825 1962 1826 1963 \rewriterules 1827 1964 \begin{lstlisting} 1828 a & b §\rewrite§ ?&?( a, b )§\use{?&?}§1965 a & b @\rewrite@ ?&?( a, b )@\use{?&?}@ 1829 1966 \end{lstlisting} 1830 1967 … … 1838 1975 long long unsigned int ?&?( long long unsigned int, long long unsigned int ); 1839 1976 \end{lstlisting} 1840 For every extended integer type \lstinline @X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@there exist1977 For every extended integer type \lstinline$X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$ there exist 1841 1978 % Don't use predefined: keep this out of prelude.cf. 1842 1979 \begin{lstlisting} … … 1853 1990 \lhs{exclusive-OR-expression} 1854 1991 \rhs \nonterm{AND-expression} 1855 \rhs \nonterm{exclusive-OR-expression} \lstinline @^@\nonterm{AND-expression}1992 \rhs \nonterm{exclusive-OR-expression} \lstinline$^$ \nonterm{AND-expression} 1856 1993 \end{syntax} 1857 1994 1858 1995 \rewriterules 1859 1996 \begin{lstlisting} 1860 a ^ b §\rewrite§ ?^?( a, b )§\use{?^?}§1997 a ^ b @\rewrite@ ?^?( a, b )@\use{?^?}@ 1861 1998 \end{lstlisting} 1862 1999 … … 1870 2007 long long unsigned int ?^?( long long unsigned int, long long unsigned int ); 1871 2008 \end{lstlisting} 1872 For every extended integer type \lstinline @X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@there exist2009 For every extended integer type \lstinline$X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$ there exist 1873 2010 % Don't use predefined: keep this out of prelude.cf. 1874 2011 \begin{lstlisting} … … 1885 2022 \lhs{inclusive-OR-expression} 1886 2023 \rhs \nonterm{exclusive-OR-expression} 1887 \rhs \nonterm{inclusive-OR-expression} \lstinline @|@\nonterm{exclusive-OR-expression}2024 \rhs \nonterm{inclusive-OR-expression} \lstinline$|$ \nonterm{exclusive-OR-expression} 1888 2025 \end{syntax} 1889 2026 1890 2027 \rewriterules\use{?"|?} 1891 2028 \begin{lstlisting} 1892 a | b §\rewrite§?|?( a, b )2029 a | b @\rewrite@ ?|?( a, b ) 1893 2030 \end{lstlisting} 1894 2031 … … 1902 2039 long long unsigned int ?|?( long long unsigned int, long long unsigned int ); 1903 2040 \end{lstlisting} 1904 For every extended integer type \lstinline @X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@there exist2041 For every extended integer type \lstinline$X$ with \Index{integer conversion rank} greater than the rank of \lstinline$int$ there exist 1905 2042 % Don't use predefined: keep this out of prelude.cf. 1906 2043 \begin{lstlisting} … … 1917 2054 \lhs{logical-AND-expression} 1918 2055 \rhs \nonterm{inclusive-OR-expression} 1919 \rhs \nonterm{logical-AND-expression} \lstinline @&&@\nonterm{inclusive-OR-expression}2056 \rhs \nonterm{logical-AND-expression} \lstinline$&&$ \nonterm{inclusive-OR-expression} 1920 2057 \end{syntax} 1921 2058 1922 \semantics The operands of the expression ``\lstinline @a && b@'' are treated as1923 ``\lstinline @(int)((a)!=0)@'' and ``\lstinline@(int)((b)!=0)@'', which shall both be unambiguous.1924 The expression has only one interpretation, which is of type \lstinline @int@.1925 \begin{rationale} 1926 When the operands of a logical expression are values of built-in types, and ``\lstinline @!=@'' has not been redefined for those types, the compiler can optimize away the function calls.1927 1928 A common C idiom omits comparisons to \lstinline @0@in the controlling expressions of loops and1929 \lstinline @if@statements.1930 For instance, the loop below iterates as long as \lstinline @rp@ points at a \lstinline@Rational@value that is non-zero.1931 1932 \begin{lstlisting} 1933 extern otype Rational; §\use{Rational}§1934 extern const Rational 0; §\use{0}§2059 \semantics The operands of the expression ``\lstinline$a && b$'' are treated as 2060 ``\lstinline$(int)((a)!=0)$'' and ``\lstinline$(int)((b)!=0)$'', which shall both be unambiguous. 2061 The expression has only one interpretation, which is of type \lstinline$int$. 2062 \begin{rationale} 2063 When the operands of a logical expression are values of built-in types, and ``\lstinline$!=$'' has not been redefined for those types, the compiler can optimize away the function calls. 2064 2065 A common C idiom omits comparisons to \lstinline$0$ in the controlling expressions of loops and 2066 \lstinline$if$ statements. 2067 For instance, the loop below iterates as long as \lstinline$rp$ points at a \lstinline$Rational$ value that is non-zero. 2068 2069 \begin{lstlisting} 2070 extern otype Rational;@\use{Rational}@ 2071 extern const Rational 0;@\use{0}@ 1935 2072 extern int ?!=?( Rational, Rational ); 1936 2073 Rational *rp; 1937 2074 while ( rp && *rp ) { ... } 1938 2075 \end{lstlisting} 1939 The logical expression calls the \lstinline @Rational@ inequality operator, passing it \lstinline@*rp@ and the \lstinline@Rational 0@, and getting a 1 or 0 as a result.1940 In contrast, {\CC} would apply a programmer-defined \lstinline @Rational@-to-\lstinline@int@ conversion to \lstinline@*rp@in the equivalent situation.1941 The conversion to \lstinline @int@would produce a general integer value, which is unfortunate, and possibly dangerous if the conversion was not written with this situation in mind.2076 The logical expression calls the \lstinline$Rational$ inequality operator, passing it \lstinline$*rp$ and the \lstinline$Rational 0$, and getting a 1 or 0 as a result. 2077 In contrast, {\CC} would apply a programmer-defined \lstinline$Rational$-to-\lstinline$int$ conversion to \lstinline$*rp$ in the equivalent situation. 2078 The conversion to \lstinline$int$ would produce a general integer value, which is unfortunate, and possibly dangerous if the conversion was not written with this situation in mind. 1942 2079 \end{rationale} 1943 2080 … … 1948 2085 \lhs{logical-OR-expression} 1949 2086 \rhs \nonterm{logical-AND-expression} 1950 \rhs \nonterm{logical-OR-expression} \lstinline @||@\nonterm{logical-AND-expression}2087 \rhs \nonterm{logical-OR-expression} \lstinline$||$ \nonterm{logical-AND-expression} 1951 2088 \end{syntax} 1952 2089 1953 2090 \semantics 1954 2091 1955 The operands of the expression ``\lstinline @a || b@'' are treated as ``\lstinline@(int)((a)!=0)@'' and ``\lstinline@(int)((b))!=0)@'', which shall both be unambiguous.1956 The expression has only one interpretation, which is of type \lstinline @int@.2092 The operands of the expression ``\lstinline$a || b$'' are treated as ``\lstinline$(int)((a)!=0)$'' and ``\lstinline$(int)((b))!=0)$'', which shall both be unambiguous. 2093 The expression has only one interpretation, which is of type \lstinline$int$. 1957 2094 1958 2095 … … 1962 2099 \lhs{conditional-expression} 1963 2100 \rhs \nonterm{logical-OR-expression} 1964 \rhs \nonterm{logical-OR-expression} \lstinline @?@\nonterm{expression}1965 \lstinline @:@\nonterm{conditional-expression}2101 \rhs \nonterm{logical-OR-expression} \lstinline$?$ \nonterm{expression} 2102 \lstinline$:$ \nonterm{conditional-expression} 1966 2103 \end{syntax} 1967 2104 1968 2105 \semantics 1969 In the conditional expression\use{?:} ``\lstinline @a?b:c@'', if the second and third operands both have an interpretation with \lstinline@void@ type, then the expression has an interpretation with type \lstinline@void@, equivalent to2106 In the conditional expression\use{?:} ``\lstinline$a?b:c$'', if the second and third operands both have an interpretation with \lstinline$void$ type, then the expression has an interpretation with type \lstinline$void$, equivalent to 1970 2107 \begin{lstlisting} 1971 2108 ( int)(( a)!=0) ? ( void)( b) : ( void)( c) 1972 2109 \end{lstlisting} 1973 2110 1974 If the second and third operands both have interpretations with non-\lstinline @void@ types, the expression is treated as if it were the call ``\lstinline@cond((a)!=0, b, c)@'', with \lstinline@cond@declared as2111 If the second and third operands both have interpretations with non-\lstinline$void$ types, the expression is treated as if it were the call ``\lstinline$cond((a)!=0, b, c)$'', with \lstinline$cond$ declared as 1975 2112 \begin{lstlisting} 1976 2113 forall( otype T ) T cond( int, T, T ); … … 2024 2161 rand() ? i : l; 2025 2162 \end{lstlisting} 2026 The best interpretation infers the expression's type to be \lstinline @long@and applies the safe2027 \lstinline @int@-to-\lstinline@long@ conversion to \lstinline@i@.2163 The best interpretation infers the expression's type to be \lstinline$long$ and applies the safe 2164 \lstinline$int$-to-\lstinline$long$ conversion to \lstinline$i$. 2028 2165 2029 2166 \begin{lstlisting} … … 2032 2169 rand() ? cip : vip; 2033 2170 \end{lstlisting} 2034 The expression has type \lstinline @const volatile int *@, with safe conversions applied to the second and third operands to add \lstinline@volatile@ and \lstinline@const@qualifiers, respectively.2171 The expression has type \lstinline$const volatile int *$, with safe conversions applied to the second and third operands to add \lstinline$volatile$ and \lstinline$const$ qualifiers, respectively. 2035 2172 2036 2173 \begin{lstlisting} 2037 2174 rand() ? cip : 0; 2038 2175 \end{lstlisting} 2039 The expression has type \lstinline @const int *@, with a specialization conversion applied to2040 \lstinline @0@.2176 The expression has type \lstinline$const int *$, with a specialization conversion applied to 2177 \lstinline$0$. 2041 2178 2042 2179 … … 2049 2186 \nonterm{assignment-expression} 2050 2187 \lhs{assignment-operator} one of 2051 \rhs \lstinline @=@\ \ \lstinline@*=@\ \ \lstinline@/=@\ \ \lstinline@%=@\ \ \lstinline@+=@\ \ \lstinline@-=@\ \2052 \lstinline @<<=@\ \ \lstinline@>>=@\ \ \lstinline@&=@\ \ \lstinline@^=@\ \ \lstinline@|=@2188 \rhs \lstinline$=$\ \ \lstinline$*=$\ \ \lstinline$/=$\ \ \lstinline$%=$\ \ \lstinline$+=$\ \ \lstinline$-=$\ \ 2189 \lstinline$<<=$\ \ \lstinline$>>=$\ \ \lstinline$&=$\ \ \lstinline$^=$\ \ \lstinline$|=$ 2053 2190 \end{syntax} 2054 2191 … … 2059 2196 \use{?>>=?}\use{?&=?}\use{?^=?}\use{?"|=?}%use{?<<=?} 2060 2197 \begin{lstlisting} 2061 a §$\leftarrow$§ b §\rewrite§ ?§$\leftarrow$§?( &( a ), b )2198 a @$\leftarrow$@ b @\rewrite@ ?@$\leftarrow$@?( &( a ), b ) 2062 2199 \end{lstlisting} 2063 2200 2064 2201 \semantics 2065 2202 Each interpretation of the left operand of an assignment expression is considered separately. 2066 For each interpretation that is a bit-field or is declared with the \lstinline @register@storage class specifier, the expression has one valid interpretation, with the type of the left operand.2203 For each interpretation that is a bit-field or is declared with the \lstinline$register$ storage class specifier, the expression has one valid interpretation, with the type of the left operand. 2067 2204 The right operand is cast to that type, and the assignment expression is ambiguous if either operand is. 2068 2205 For the remaining interpretations, the expression is rewritten, and the interpretations of the assignment expression are the interpretations of the corresponding function call. … … 2297 2434 \end{lstlisting} 2298 2435 \begin{rationale} 2299 The pattern of overloadings for simple assignment resembles that of pointer increment and decrement, except that the polymorphic pointer assignment functions declare a \lstinline @dtype@ parameter, instead of a \lstinline@type@parameter, because the left operand may be a pointer to an incomplete type.2300 \end{rationale} 2301 2302 For every complete structure or union type \lstinline @S@there exist2436 The pattern of overloadings for simple assignment resembles that of pointer increment and decrement, except that the polymorphic pointer assignment functions declare a \lstinline$dtype$ parameter, instead of a \lstinline$type$ parameter, because the left operand may be a pointer to an incomplete type. 2437 \end{rationale} 2438 2439 For every complete structure or union type \lstinline$S$ there exist 2303 2440 % Don't use predefined: keep this out of prelude.cf. 2304 2441 \begin{lstlisting} … … 2306 2443 \end{lstlisting} 2307 2444 2308 For every extended integer type \lstinline @X@there exist2445 For every extended integer type \lstinline$X$ there exist 2309 2446 % Don't use predefined: keep this out of prelude.cf. 2310 2447 \begin{lstlisting} … … 2312 2449 \end{lstlisting} 2313 2450 2314 For every complete enumerated type \lstinline @E@there exist2451 For every complete enumerated type \lstinline$E$ there exist 2315 2452 % Don't use predefined: keep this out of prelude.cf. 2316 2453 \begin{lstlisting} … … 2318 2455 \end{lstlisting} 2319 2456 \begin{rationale} 2320 The right-hand argument is \lstinline @int@ because enumeration constants have type \lstinline@int@.2457 The right-hand argument is \lstinline$int$ because enumeration constants have type \lstinline$int$. 2321 2458 \end{rationale} 2322 2459 … … 2579 2716 \end{lstlisting} 2580 2717 2581 For every extended integer type \lstinline @X@there exist2718 For every extended integer type \lstinline$X$ there exist 2582 2719 % Don't use predefined: keep this out of prelude.cf. 2583 2720 \begin{lstlisting} … … 2594 2731 \end{lstlisting} 2595 2732 2596 For every complete enumerated type \lstinline @E@there exist2733 For every complete enumerated type \lstinline$E$ there exist 2597 2734 % Don't use predefined: keep this out of prelude.cf. 2598 2735 \begin{lstlisting} … … 2615 2752 \lhs{expression} 2616 2753 \rhs \nonterm{assignment-expression} 2617 \rhs \nonterm{expression} \lstinline @,@\nonterm{assignment-expression}2754 \rhs \nonterm{expression} \lstinline$,$ \nonterm{assignment-expression} 2618 2755 \end{syntax} 2619 2756 2620 2757 \semantics 2621 In the comma expression ``\lstinline @a, b@'', the first operand is interpreted as2622 ``\lstinline @( void )(a)@'', which shall be unambiguous\index{ambiguous interpretation}.2758 In the comma expression ``\lstinline$a, b$'', the first operand is interpreted as 2759 ``\lstinline$( void )(a)$'', which shall be unambiguous\index{ambiguous interpretation}. 2623 2760 The interpretations of the expression are the interpretations of the second operand. 2624 2761 … … 2655 2792 { ... } 2656 2793 \end{lstlisting} 2657 Without the rule, \lstinline @Complex@would be a type in the first case, and a parameter name in the second.2794 Without the rule, \lstinline$Complex$ would be a type in the first case, and a parameter name in the second. 2658 2795 \end{rationale} 2659 2796 … … 2681 2818 \examples 2682 2819 \begin{lstlisting} 2683 struct point { §\impl{point}§2820 struct point {@\impl{point}@ 2684 2821 int x, y; 2685 2822 }; 2686 struct color_point { §\impl{color_point}§2823 struct color_point {@\impl{color_point}@ 2687 2824 enum { RED, BLUE, GREEN } color; 2688 2825 struct point; … … 2691 2828 cp.x = 0; 2692 2829 cp.color = RED; 2693 struct literal { §\impl{literal}§2830 struct literal {@\impl{literal}@ 2694 2831 enum { NUMBER, STRING } tag; 2695 2832 union { … … 2712 2849 \begin{syntax} 2713 2850 \lhs{forall-specifier} 2714 \rhs \lstinline @forall@ \lstinline@(@ \nonterm{type-parameter-list} \lstinline@)@2851 \rhs \lstinline$forall$ \lstinline$($ \nonterm{type-parameter-list} \lstinline$)$ 2715 2852 \end{syntax} 2716 2853 … … 2724 2861 } mkPair( T, T ); // illegal 2725 2862 \end{lstlisting} 2726 If an instance of \lstinline @struct Pair@was declared later in the current scope, what would the members' type be?2863 If an instance of \lstinline$struct Pair$ was declared later in the current scope, what would the members' type be? 2727 2864 \end{rationale} 2728 2865 \end{comment} … … 2731 2868 The \nonterm{type-parameter-list}s and assertions of the \nonterm{forall-specifier}s declare type identifiers, function and object identifiers with \Index{no linkage}. 2732 2869 2733 If, in the declaration ``\lstinline @T D@'', \lstinline@T@contains \nonterm{forall-specifier}s and2734 \lstinline @D@has the form2735 \begin{lstlisting} 2736 D( §\normalsize\nonterm{parameter-type-list}§)2737 \end{lstlisting} then a type identifier declared by one of the \nonterm{forall-specifier}s is an \define{inferred parameter} of the function declarator if and only if it is not an inferred parameter of a function declarator in \lstinline @D@, and it is used in the type of a parameter in the following2870 If, in the declaration ``\lstinline$T D$'', \lstinline$T$ contains \nonterm{forall-specifier}s and 2871 \lstinline$D$ has the form 2872 \begin{lstlisting} 2873 D( @\normalsize\nonterm{parameter-type-list}@ ) 2874 \end{lstlisting} then a type identifier declared by one of the \nonterm{forall-specifier}s is an \define{inferred parameter} of the function declarator if and only if it is not an inferred parameter of a function declarator in \lstinline$D$, and it is used in the type of a parameter in the following 2738 2875 \nonterm{type-parameter-list} or it and an inferred parameter are used as arguments of a 2739 2876 \Index{specification} in one of the \nonterm{forall-specifier}s. … … 2746 2883 If this restriction were lifted, it would be possible to write 2747 2884 \begin{lstlisting} 2748 forall( otype T ) T * alloc( void ); §\use{alloc}§int *p = alloc();2749 \end{lstlisting} 2750 Here \lstinline @alloc()@ would receive \lstinline@int@as an inferred argument, and return an2751 \lstinline @int *@.2752 In general, if a call to \lstinline @alloc()@ is a subexpression of an expression involving polymorphic functions and overloaded identifiers, there could be considerable distance between the call and the subexpression that causes \lstinline@T@to be bound.2753 2754 With the current restriction, \lstinline @alloc()@must be given an argument that determines2755 \lstinline @T@:2756 \begin{lstlisting} 2757 forall( otype T ) T * alloc( T initial_value ); §\use{alloc}§2885 forall( otype T ) T * alloc( void );@\use{alloc}@ int *p = alloc(); 2886 \end{lstlisting} 2887 Here \lstinline$alloc()$ would receive \lstinline$int$ as an inferred argument, and return an 2888 \lstinline$int *$. 2889 In general, if a call to \lstinline$alloc()$ is a subexpression of an expression involving polymorphic functions and overloaded identifiers, there could be considerable distance between the call and the subexpression that causes \lstinline$T$ to be bound. 2890 2891 With the current restriction, \lstinline$alloc()$ must be given an argument that determines 2892 \lstinline$T$: 2893 \begin{lstlisting} 2894 forall( otype T ) T * alloc( T initial_value );@\use{alloc}@ 2758 2895 \end{lstlisting} 2759 2896 \end{rationale} … … 2780 2917 forall( otype T ) T fT( T ); 2781 2918 \end{lstlisting} 2782 \lstinline @fi()@ takes an \lstinline@int@ and returns an \lstinline@int@. \lstinline@fT()@takes a2783 \lstinline @T@ and returns a \lstinline@T@, for any type \lstinline@T@.2919 \lstinline$fi()$ takes an \lstinline$int$ and returns an \lstinline$int$. \lstinline$fT()$ takes a 2920 \lstinline$T$ and returns a \lstinline$T$, for any type \lstinline$T$. 2784 2921 \begin{lstlisting} 2785 2922 int (*pfi )( int ) = fi; 2786 2923 forall( otype T ) T (*pfT )( T ) = fT; 2787 2924 \end{lstlisting} 2788 \lstinline @pfi@ and \lstinline@pfT@ are pointers to functions. \lstinline@pfT@is not polymorphic, but the function it points at is.2925 \lstinline$pfi$ and \lstinline$pfT$ are pointers to functions. \lstinline$pfT$ is not polymorphic, but the function it points at is. 2789 2926 \begin{lstlisting} 2790 2927 int (*fvpfi( void ))( int ) { … … 2795 2932 } 2796 2933 \end{lstlisting} 2797 \lstinline @fvpfi()@ and \lstinline@fvpfT()@ are functions taking no arguments and returning pointers to functions. \lstinline@fvpfT()@is monomorphic, but the function that its return value points at is polymorphic.2934 \lstinline$fvpfi()$ and \lstinline$fvpfT()$ are functions taking no arguments and returning pointers to functions. \lstinline$fvpfT()$ is monomorphic, but the function that its return value points at is polymorphic. 2798 2935 \begin{lstlisting} 2799 2936 forall( otype T ) int ( *fTpfi( T ) )( int ); … … 2801 2938 forall( otype T, otype U ) U ( *fTpfU( T ) )( U ); 2802 2939 \end{lstlisting} 2803 \lstinline @fTpfi()@is a polymorphic function that returns a pointer to a monomorphic function taking an integer and returning an integer.2804 It could return \lstinline @pfi@. \lstinline@fTpfT()@is subtle: it is a polymorphic function returning a \emph{monomorphic} function taking and returning2805 \lstinline @T@, where \lstinline@T@ is an inferred parameter of \lstinline@fTpfT()@.2806 For instance, in the expression ``\lstinline @fTpfT(17)@'', \lstinline@T@ is inferred to be \lstinline@int@, and the returned value would have type \lstinline@int ( * )( int )@. ``\lstinline@fTpfT(17)(13)@'' and2807 ``\lstinline @fTpfT("yes")("no")@'' are legal, but ``\lstinline@fTpfT(17)("no")@'' is illegal.2808 \lstinline @fTpfU()@ is polymorphic ( in type \lstinline@T@), and returns a pointer to a function that is polymorphic ( in type \lstinline@U@). ``\lstinline@f5(17)("no")@'' is a legal expression of type2809 \lstinline @char *@.2940 \lstinline$fTpfi()$ is a polymorphic function that returns a pointer to a monomorphic function taking an integer and returning an integer. 2941 It could return \lstinline$pfi$. \lstinline$fTpfT()$ is subtle: it is a polymorphic function returning a \emph{monomorphic} function taking and returning 2942 \lstinline$T$, where \lstinline$T$ is an inferred parameter of \lstinline$fTpfT()$. 2943 For instance, in the expression ``\lstinline$fTpfT(17)$'', \lstinline$T$ is inferred to be \lstinline$int$, and the returned value would have type \lstinline$int ( * )( int )$. ``\lstinline$fTpfT(17)(13)$'' and 2944 ``\lstinline$fTpfT("yes")("no")$'' are legal, but ``\lstinline$fTpfT(17)("no")$'' is illegal. 2945 \lstinline$fTpfU()$ is polymorphic ( in type \lstinline$T$), and returns a pointer to a function that is polymorphic ( in type \lstinline$U$). ``\lstinline$f5(17)("no")$'' is a legal expression of type 2946 \lstinline$char *$. 2810 2947 \begin{lstlisting} 2811 2948 forall( otype T, otype U, otype V ) U * f( T *, U, V * const ); 2812 2949 forall( otype U, otype V, otype W ) U * g( V *, U, W * const ); 2813 2950 \end{lstlisting} 2814 The functions \lstinline @f()@ and \lstinline@g()@have compatible types.2951 The functions \lstinline$f()$ and \lstinline$g()$ have compatible types. 2815 2952 Let \(f\) and \(g\) be their types; 2816 then \(f_1\) = \lstinline @T@, \(f_2\) = \lstinline@U@, \(f_3\) = \lstinline@V@, \(g_1\)2817 = \lstinline @V@, \(g_2\) = \lstinline@U@, and \(g_3\) = \lstinline@W@.2953 then \(f_1\) = \lstinline$T$, \(f_2\) = \lstinline$U$, \(f_3\) = \lstinline$V$, \(g_1\) 2954 = \lstinline$V$, \(g_2\) = \lstinline$U$, and \(g_3\) = \lstinline$W$. 2818 2955 Replacing every \(f_i\) by \(g_i\) in \(f\) gives 2819 2956 \begin{lstlisting} … … 2821 2958 \end{lstlisting} which has a return type and parameter list that is compatible with \(g\). 2822 2959 \begin{rationale} 2823 The word ``\lstinline @type@'' in a forall specifier is redundant at the moment, but I want to leave room for inferred parameters of ordinary types in case parameterized types get added one day.2960 The word ``\lstinline$type$'' in a forall specifier is redundant at the moment, but I want to leave room for inferred parameters of ordinary types in case parameterized types get added one day. 2824 2961 2825 2962 Even without parameterized types, I might try to allow … … 2847 2984 \subsection{Type qualifiers} 2848 2985 2849 \CFA defines a new type qualifier \lstinline @lvalue@\impl{lvalue}\index{lvalue}.2986 \CFA defines a new type qualifier \lstinline$lvalue$\impl{lvalue}\index{lvalue}. 2850 2987 \begin{syntax} 2851 2988 \oldlhs{type-qualifier} 2852 \rhs \lstinline @lvalue@2989 \rhs \lstinline$lvalue$ 2853 2990 \end{syntax} 2854 2991 2855 2992 \constraints 2856 \ Indexc{restrict} Types other than type parameters and pointer types whose referenced type is an object type shall not be restrict-qualified.2993 \lstinline$restrict$\index{register@{\lstinline$restrict$}} Types other than type parameters and pointer types whose referenced type is an object type shall not be restrict-qualified. 2857 2994 2858 2995 \semantics 2859 An object's type may be a restrict-qualified type parameter. 2860 \lstinline@restrict@ does not establish any special semantics in that case. 2996 An object's type may be a restrict-qualified type parameter. \lstinline$restrict$ does not establish any special semantics in that case. 2861 2997 2862 2998 \begin{rationale} … … 2864 3000 \end{rationale} 2865 3001 2866 \lstinline @lvalue@may be used to qualify the return type of a function type.2867 Let \lstinline @T@be an unqualified version of a type;3002 \lstinline$lvalue$ may be used to qualify the return type of a function type. 3003 Let \lstinline$T$ be an unqualified version of a type; 2868 3004 then the result of calling a function with return type 2869 \lstinline @lvalue T@ is a \Index{modifiable lvalue} of type \lstinline@T@.2870 \lstinline @const@\use{const} and \lstinline@volatile@\use{volatile} qualifiers may also be added to indicate that the function result is a constant or volatile lvalue.2871 \begin{rationale} 2872 The \lstinline @const@ and \lstinline@volatile@ qualifiers can only be sensibly used to qualify the return type of a function if the \lstinline@lvalue@qualifier is also used.3005 \lstinline$lvalue T$ is a \Index{modifiable lvalue} of type \lstinline$T$. 3006 \lstinline$const$\use{const} and \lstinline$volatile$\use{volatile} qualifiers may also be added to indicate that the function result is a constant or volatile lvalue. 3007 \begin{rationale} 3008 The \lstinline$const$ and \lstinline$volatile$ qualifiers can only be sensibly used to qualify the return type of a function if the \lstinline$lvalue$ qualifier is also used. 2873 3009 \end{rationale} 2874 3010 … … 2877 3013 2878 3014 \begin{rationale} 2879 \lstinline @lvalue@ provides some of the functionality of {\CC}'s ``\lstinline@T&@'' ( reference to object of type \lstinline@T@) type.3015 \lstinline$lvalue$ provides some of the functionality of {\CC}'s ``\lstinline$T&$'' ( reference to object of type \lstinline$T$) type. 2880 3016 Reference types have four uses in {\CC}. 2881 3017 \begin{itemize} 2882 3018 \item 2883 They are necessary for user-defined operators that return lvalues, such as ``subscript'' and ``dereference''. 2884 2885 \item 2886 A reference can be used to define an alias for a complicated lvalue expression, as a way of getting some of the functionality of the Pascal \lstinline@with@ statement. 3019 They are necessary for user-defined operators that return lvalues, such as ``subscript'' and 3020 ``dereference''. 3021 3022 \item 3023 A reference can be used to define an alias for a complicated lvalue expression, as a way of getting some of the functionality of the Pascal \lstinline$with$ statement. 2887 3024 The following {\CC} code gives an example. 2888 3025 \begin{lstlisting} … … 2897 3034 A reference parameter can be used to allow a function to modify an argument without forcing the caller to pass the address of the argument. 2898 3035 This is most useful for user-defined assignment operators. 2899 In {\CC}, plain assignment is done by a function called ``\lstinline @operator=@'', and the two expressions3036 In {\CC}, plain assignment is done by a function called ``\lstinline$operator=$'', and the two expressions 2900 3037 \begin{lstlisting} 2901 3038 a = b; 2902 3039 operator=( a, b ); 2903 3040 \end{lstlisting} are equivalent. 2904 If \lstinline @a@ and \lstinline@b@ are of type \lstinline@T@, then the first parameter of \lstinline@operator=@ must have type ``\lstinline@T&@''.3041 If \lstinline$a$ and \lstinline$b$ are of type \lstinline$T$, then the first parameter of \lstinline$operator=$ must have type ``\lstinline$T&$''. 2905 3042 It cannot have type 2906 \lstinline @T@, because then assignment couldn't alter the variable, and it can't have type2907 ``\lstinline @T *@'', because the assignment would have to be written ``\lstinline@&a = b;@''.2908 2909 In the case of user-defined operators, this could just as well be handled by using pointer types and by changing the rewrite rules so that ``\lstinline @a = b;@'' is equivalent to2910 ``\lstinline @operator=(&( a), b )@''.2911 Reference parameters of ``normal'' functions are Bad Things, because they remove a useful property of C function calls: an argument can only be modified by a function if it is preceded by ``\lstinline @&@''.3043 \lstinline$T$, because then assignment couldn't alter the variable, and it can't have type 3044 ``\lstinline$T *$'', because the assignment would have to be written ``\lstinline$&a = b;$''. 3045 3046 In the case of user-defined operators, this could just as well be handled by using pointer types and by changing the rewrite rules so that ``\lstinline$a = b;$'' is equivalent to 3047 ``\lstinline$operator=(&( a), b )$''. 3048 Reference parameters of ``normal'' functions are Bad Things, because they remove a useful property of C function calls: an argument can only be modified by a function if it is preceded by ``\lstinline$&$''. 2912 3049 2913 3050 \item 2914 3051 References to \Index{const-qualified} types can be used instead of value parameters. Given the 2915 {\CC} function call ``\lstinline @fiddle( a_thing )@'', where the type of \lstinline@a_thing@is2916 \lstinline @Thing@, the type of \lstinline@fiddle@could be either of3052 {\CC} function call ``\lstinline$fiddle( a_thing )$'', where the type of \lstinline$a_thing$ is 3053 \lstinline$Thing$, the type of \lstinline$fiddle$ could be either of 2917 3054 \begin{lstlisting} 2918 3055 void fiddle( Thing ); 2919 3056 void fiddle( const Thing & ); 2920 3057 \end{lstlisting} 2921 If the second form is used, then constructors and destructors are not invoked to create a temporary variable at the call site ( and it is bad style for the caller to make any assumptions about such things), and within \lstinline @fiddle@the parameter is subject to the usual problems caused by aliases.2922 The reference form might be chosen for efficiency's sake if \lstinline @Thing@s are too large or their constructors or destructors are too expensive.3058 If the second form is used, then constructors and destructors are not invoked to create a temporary variable at the call site ( and it is bad style for the caller to make any assumptions about such things), and within \lstinline$fiddle$ the parameter is subject to the usual problems caused by aliases. 3059 The reference form might be chosen for efficiency's sake if \lstinline$Thing$s are too large or their constructors or destructors are too expensive. 2923 3060 An implementation may switch between them without causing trouble for well-behaved clients. 2924 3061 This leaves the implementor to define ``too large'' and ``too expensive''. … … 2928 3065 void fiddle( const volatile Thing ); 2929 3066 \end{lstlisting} with call-by-reference. 2930 Since it knows all about the size of \lstinline @Thing@s and the parameter passing mechanism, it should be able to come up with a better definition of ``too large'', and may be able to make a good guess at ``too expensive''.3067 Since it knows all about the size of \lstinline$Thing$s and the parameter passing mechanism, it should be able to come up with a better definition of ``too large'', and may be able to make a good guess at ``too expensive''. 2931 3068 \end{itemize} 2932 3069 … … 2948 3085 \begin{syntax} 2949 3086 \lhs{spec-definition} 2950 \rhs \lstinline @spec@\nonterm{identifier}2951 \lstinline @(@ \nonterm{type-parameter-list} \lstinline@)@2952 \lstinline @{@ \nonterm{spec-declaration-list}\opt \lstinline@}@3087 \rhs \lstinline$spec$ \nonterm{identifier} 3088 \lstinline$($ \nonterm{type-parameter-list} \lstinline$)$ 3089 \lstinline${$ \nonterm{spec-declaration-list}\opt \lstinline$}$ 2953 3090 \lhs{spec-declaration-list} 2954 \rhs \nonterm{spec-declaration} \lstinline @;@2955 \rhs \nonterm{spec-declaration-list} \nonterm{spec-declaration} \lstinline @;@3091 \rhs \nonterm{spec-declaration} \lstinline$;$ 3092 \rhs \nonterm{spec-declaration-list} \nonterm{spec-declaration} \lstinline$;$ 2956 3093 \lhs{spec-declaration} 2957 3094 \rhs \nonterm{specifier-qualifier-list} \nonterm{declarator-list} 2958 3095 \lhs{declarator-list} 2959 3096 \rhs \nonterm{declarator} 2960 \rhs \nonterm{declarator-list} \lstinline @,@\nonterm{declarator}3097 \rhs \nonterm{declarator-list} \lstinline$,$ \nonterm{declarator} 2961 3098 \end{syntax} 2962 3099 \begin{rationale} … … 2980 3117 \rhs \nonterm{assertion-list} \nonterm{assertion} 2981 3118 \lhs{assertion} 2982 \rhs \lstinline @|@ \nonterm{identifier} \lstinline@(@ \nonterm{type-name-list} \lstinline@)@2983 \rhs \lstinline @|@\nonterm{spec-declaration}3119 \rhs \lstinline$|$ \nonterm{identifier} \lstinline$($ \nonterm{type-name-list} \lstinline$)$ 3120 \rhs \lstinline$|$ \nonterm{spec-declaration} 2984 3121 \lhs{type-name-list} 2985 3122 \rhs \nonterm{type-name} 2986 \rhs \nonterm{type-name-list} \lstinline @,@\nonterm{type-name}3123 \rhs \nonterm{type-name-list} \lstinline$,$ \nonterm{type-name} 2987 3124 \end{syntax} 2988 3125 … … 2991 3128 The \nonterm{type-name-list} shall contain one \nonterm{type-name} argument for each \nonterm{type-parameter} in that specification's \nonterm{spec-parameter-list}. 2992 3129 If the 2993 \nonterm{type-parameter} uses type-class \lstinline @type@\use{type}, the argument shall be the type name of an \Index{object type};2994 if it uses \lstinline @dtype@, the argument shall be the type name of an object type or an \Index{incomplete type};2995 and if it uses \lstinline @ftype@, the argument shall be the type name of a \Index{function type}.3130 \nonterm{type-parameter} uses type-class \lstinline$type$\use{type}, the argument shall be the type name of an \Index{object type}; 3131 if it uses \lstinline$dtype$, the argument shall be the type name of an object type or an \Index{incomplete type}; 3132 and if it uses \lstinline$ftype$, the argument shall be the type name of a \Index{function type}. 2996 3133 2997 3134 \semantics … … 3006 3143 \examples 3007 3144 \begin{lstlisting} 3008 forall( otype T | T ?*?( T, T )) §\use{?*?}§3009 T square( T val ) { §\impl{square}§3145 forall( otype T | T ?*?( T, T ))@\use{?*?}@ 3146 T square( T val ) {@\impl{square}@ 3010 3147 return val + val; 3011 3148 } 3012 trait summable( otype T ) { §\impl{summable}§3013 T ?+=?( T *, T ); §\use{?+=?}§3014 const T 0; §\use{0}§3149 trait summable( otype T ) {@\impl{summable}@ 3150 T ?+=?( T *, T );@\use{?+=?}@ 3151 const T 0;@\use{0}@ 3015 3152 }; 3016 trait list_of( otype List, otype Element ) { §\impl{list_of}§3153 trait list_of( otype List, otype Element ) {@\impl{list_of}@ 3017 3154 Element car( List ); 3018 3155 List cdr( List ); … … 3023 3160 trait sum_list( otype List, otype Element | summable( Element ) | list_of( List, Element ) ) {}; 3024 3161 \end{lstlisting} 3025 \lstinline @sum_list@contains seven declarations, which describe a list whose elements can be added up.3026 The assertion ``\lstinline @|sum_list( i_list, int )@''\use{sum_list} produces the assertion parameters3162 \lstinline$sum_list$ contains seven declarations, which describe a list whose elements can be added up. 3163 The assertion ``\lstinline$|sum_list( i_list, int )$''\use{sum_list} produces the assertion parameters 3027 3164 \begin{lstlisting} 3028 3165 int ?+=?( int *, int ); … … 3041 3178 \lhs{type-parameter-list} 3042 3179 \rhs \nonterm{type-parameter} 3043 \rhs \nonterm{type-parameter-list} \lstinline @,@\nonterm{type-parameter}3180 \rhs \nonterm{type-parameter-list} \lstinline$,$ \nonterm{type-parameter} 3044 3181 \lhs{type-parameter} 3045 3182 \rhs \nonterm{type-class} \nonterm{identifier} \nonterm{assertion-list}\opt 3046 3183 \lhs{type-class} 3047 \rhs \lstinline @type@3048 \rhs \lstinline @dtype@3049 \rhs \lstinline @ftype@3184 \rhs \lstinline$type$ 3185 \rhs \lstinline$dtype$ 3186 \rhs \lstinline$ftype$ 3050 3187 \lhs{type-declaration} 3051 \rhs \nonterm{storage-class-specifier}\opt \lstinline @type@\nonterm{type-declarator-list} \verb|;|3188 \rhs \nonterm{storage-class-specifier}\opt \lstinline$type$ \nonterm{type-declarator-list} \verb|;| 3052 3189 \lhs{type-declarator-list} 3053 3190 \rhs \nonterm{type-declarator} 3054 \rhs \nonterm{type-declarator-list} \lstinline @,@\nonterm{type-declarator}3191 \rhs \nonterm{type-declarator-list} \lstinline$,$ \nonterm{type-declarator} 3055 3192 \lhs{type-declarator} 3056 \rhs \nonterm{identifier} \nonterm{assertion-list}\opt \lstinline @=@\nonterm{type-name}3193 \rhs \nonterm{identifier} \nonterm{assertion-list}\opt \lstinline$=$ \nonterm{type-name} 3057 3194 \rhs \nonterm{identifier} \nonterm{assertion-list}\opt 3058 3195 \end{syntax} … … 3065 3202 3066 3203 An identifier declared by a \nonterm{type-parameter} has \Index{no linkage}. 3067 Identifiers declared with type-class \lstinline @type@\use{type} are \Index{object type}s;3204 Identifiers declared with type-class \lstinline$type$\use{type} are \Index{object type}s; 3068 3205 those declared with type-class 3069 \lstinline @dtype@\use{dtype} are \Index{incomplete type}s;3206 \lstinline$dtype$\use{dtype} are \Index{incomplete type}s; 3070 3207 and those declared with type-class 3071 \lstinline @ftype@\use{ftype} are \Index{function type}s.3208 \lstinline$ftype$\use{ftype} are \Index{function type}s. 3072 3209 The identifier has \Index{block scope} that terminates at the end of the \nonterm{spec-declaration-list} or polymorphic function that contains the \nonterm{type-parameter}. 3073 3210 … … 3077 3214 Within the scope of the declaration, \Index{implicit conversion}s can be performed between the defined type and the implementation type, and between pointers to the defined type and pointers to the implementation type. 3078 3215 3079 A type declaration without an \Index{initializer} and without a \Index{storage-class specifier} or with storage-class specifier \lstinline @static@\use{static} defines an \Index{incomplete type}.3216 A type declaration without an \Index{initializer} and without a \Index{storage-class specifier} or with storage-class specifier \lstinline$static$\use{static} defines an \Index{incomplete type}. 3080 3217 If a 3081 3218 \Index{translation unit} or \Index{block} contains one or more such declarations for an identifier, it must contain exactly one definition of the identifier ( but not in an enclosed block, which would define a new type known only within that block). … … 3097 3234 3098 3235 A type declaration without an initializer and with \Index{storage-class specifier} 3099 \lstinline @extern@\use{extern} is an \define{opaque type declaration}.3236 \lstinline$extern$\use{extern} is an \define{opaque type declaration}. 3100 3237 Opaque types are 3101 3238 \Index{object type}s. … … 3112 3249 \end{rationale} 3113 3250 3114 An \Index{incomplete type} which is not a qualified version\index{qualified type} of a type is a value of \Index{type-class} \lstinline @dtype@.3115 An object type\index{object types} which is not a qualified version of a type is a value of type-classes \lstinline @type@ and \lstinline@dtype@.3251 An \Index{incomplete type} which is not a qualified version\index{qualified type} of a type is a value of \Index{type-class} \lstinline$dtype$. 3252 An object type\index{object types} which is not a qualified version of a type is a value of type-classes \lstinline$type$ and \lstinline$dtype$. 3116 3253 A 3117 \Index{function type} is a value of type-class \lstinline @ftype@.3254 \Index{function type} is a value of type-class \lstinline$ftype$. 3118 3255 \begin{rationale} 3119 3256 Syntactically, a type value is a \nonterm{type-name}, which is a declaration for an object which omits the identifier being declared. … … 3125 3262 Type qualifiers are a weak point of C's type system. 3126 3263 Consider the standard library function 3127 \lstinline @strchr()@which, given a string and a character, returns a pointer to the first occurrence of the character in the string.3128 \begin{lstlisting} 3129 char *strchr( const char *s, int c ) { §\impl{strchr}§3264 \lstinline$strchr()$ which, given a string and a character, returns a pointer to the first occurrence of the character in the string. 3265 \begin{lstlisting} 3266 char *strchr( const char *s, int c ) {@\impl{strchr}@ 3130 3267 char real_c = c; // done because c was declared as int. 3131 3268 for ( ; *s != real_c; s++ ) … … 3134 3271 } 3135 3272 \end{lstlisting} 3136 The parameter \lstinline @s@ must be \lstinline@const char *@, because \lstinline@strchr()@ might be used to search a constant string, but the return type must be \lstinline@char *@, because the result might be used to modify a non-constant string.3273 The parameter \lstinline$s$ must be \lstinline$const char *$, because \lstinline$strchr()$ might be used to search a constant string, but the return type must be \lstinline$char *$, because the result might be used to modify a non-constant string. 3137 3274 Hence the body must perform a cast, and ( even worse) 3138 \lstinline @strchr()@provides a type-safe way to attempt to modify constant strings.3139 What is needed is some way to say that \lstinline @s@'s type might contain qualifiers, and the result type has exactly the same qualifiers.3275 \lstinline$strchr()$ provides a type-safe way to attempt to modify constant strings. 3276 What is needed is some way to say that \lstinline$s$'s type might contain qualifiers, and the result type has exactly the same qualifiers. 3140 3277 Polymorphic functions do not provide a fix for this deficiency\index{deficiencies!pointers to qualified types}, because type qualifiers are not part of type values. 3141 Instead, overloading can be used to define \lstinline @strchr()@for each combination of qualifiers.3278 Instead, overloading can be used to define \lstinline$strchr()$ for each combination of qualifiers. 3142 3279 \end{rationale} 3143 3280 … … 3164 3301 \end{lstlisting} 3165 3302 Without this restriction, \CFA might require ``module initialization'' code ( since 3166 \lstinline @Rational@ has external linkage, it must be created before any other translation unit instantiates it), and would force an ordering on the initialization of the translation unit that defines \lstinline@Huge@ and the translation that declares \lstinline@Rational@.3303 \lstinline$Rational$ has external linkage, it must be created before any other translation unit instantiates it), and would force an ordering on the initialization of the translation unit that defines \lstinline$Huge$ and the translation that declares \lstinline$Rational$. 3167 3304 3168 3305 A benefit of the restriction is that it prevents the declaration in separate translation units of types that contain each other, which would be hard to prevent otherwise. … … 3181 3318 \nonterm{struct-declaration}, type declarations can not be structure members. 3182 3319 The form of 3183 \nonterm{type-declaration} forbids arrays of, pointers to, and functions returning \lstinline @type@.3320 \nonterm{type-declaration} forbids arrays of, pointers to, and functions returning \lstinline$type$. 3184 3321 Hence the syntax of \nonterm{type-specifier} does not have to be extended to allow type-valued expressions. 3185 3322 It also side-steps the problem of type-valued expressions producing different values in different declarations. … … 3196 3333 #include <stdlib.h> 3197 3334 T * new( otype T ) { return ( T * )malloc( sizeof( T) ); }; 3198 §\ldots§int * ip = new( int );3199 \end{lstlisting} 3200 This looks sensible, but \CFA's declaration-before-use rules mean that ``\lstinline @T@'' in the function body refers to the parameter, but the ``\lstinline@T@'' in the return type refers to the meaning of \lstinline@T@ in the scope that contains \lstinline@new@;3335 @\ldots@ int * ip = new( int ); 3336 \end{lstlisting} 3337 This looks sensible, but \CFA's declaration-before-use rules mean that ``\lstinline$T$'' in the function body refers to the parameter, but the ``\lstinline$T$'' in the return type refers to the meaning of \lstinline$T$ in the scope that contains \lstinline$new$; 3201 3338 it could be undefined, or a type name, or a function or variable name. 3202 3339 Nothing good can result from such a situation. … … 3215 3352 f2( v2 ); 3216 3353 \end{lstlisting} 3217 \lstinline @V1@ is passed by value, so \lstinline@f1()@'s assignment to \lstinline@a[0]@ does not modify v1. \lstinline@V2@ is converted to a pointer, so \lstinline@f2()@ modifies \lstinline@v2[0]@.3354 \lstinline$V1$ is passed by value, so \lstinline$f1()$'s assignment to \lstinline$a[0]$ does not modify v1. \lstinline$V2$ is converted to a pointer, so \lstinline$f2()$ modifies \lstinline$v2[0]$. 3218 3355 3219 3356 A translation unit containing the declarations 3220 3357 \begin{lstlisting} 3221 extern type Complex; §\use{Complex}§// opaque type declaration3222 extern float abs( Complex ); §\use{abs}§3223 \end{lstlisting} can contain declarations of complex numbers, which can be passed to \lstinline @abs@.3224 Some other translation unit must implement \lstinline @Complex@ and \lstinline@abs@.3358 extern type Complex;@\use{Complex}@ // opaque type declaration 3359 extern float abs( Complex );@\use{abs}@ 3360 \end{lstlisting} can contain declarations of complex numbers, which can be passed to \lstinline$abs$. 3361 Some other translation unit must implement \lstinline$Complex$ and \lstinline$abs$. 3225 3362 That unit might contain the declarations 3226 3363 \begin{lstlisting} 3227 otype Complex = struct { float re, im; }; §\impl{Complex}§3228 Complex cplx_i = { 0.0, 1.0 }; §\impl{cplx_i}§3229 float abs( Complex c ) { §\impl{abs( Complex )}§3364 otype Complex = struct { float re, im; };@\impl{Complex}@ 3365 Complex cplx_i = { 0.0, 1.0 };@\impl{cplx_i}@ 3366 float abs( Complex c ) {@\impl{abs( Complex )}@ 3230 3367 return sqrt( c.re * c.re + c.im * c.im ); 3231 3368 } 3232 3369 \end{lstlisting} 3233 Note that \lstinline @c@ is implicitly converted to a \lstinline@struct@so that its components can be retrieved.3234 3235 \begin{lstlisting} 3236 otype Time_of_day = int; §\impl{Time_of_day}§// seconds since midnight.3237 Time_of_day ?+?( Time_of_day t1, int seconds ) { §\impl{?+?}§3370 Note that \lstinline$c$ is implicitly converted to a \lstinline$struct$ so that its components can be retrieved. 3371 3372 \begin{lstlisting} 3373 otype Time_of_day = int;@\impl{Time_of_day}@ // seconds since midnight. 3374 Time_of_day ?+?( Time_of_day t1, int seconds ) {@\impl{?+?}@ 3238 3375 return (( int)t1 + seconds ) % 86400; 3239 3376 } 3240 3377 \end{lstlisting} 3241 \lstinline @t1@must be cast to its implementation type to prevent infinite recursion.3378 \lstinline$t1$ must be cast to its implementation type to prevent infinite recursion. 3242 3379 3243 3380 \begin{rationale} 3244 3381 Within the scope of a type definition, an instance of the type can be viewed as having that type or as having the implementation type. 3245 In the \lstinline @Time_of_day@example, the difference is important.3382 In the \lstinline$Time_of_day$ example, the difference is important. 3246 3383 Different languages have treated the distinction between the abstraction and the implementation in different ways. 3247 3384 \begin{itemize} 3248 3385 \item 3249 Inside a Clu cluster \cite{ CLU}, the declaration of an instance states which view applies.3250 Two primitives called \lstinline @up@ and \lstinline@down@can be used to convert between the views.3251 \item 3252 The Simula class \cite{S IMULA87} is essentially a record type.3386 Inside a Clu cluster \cite{clu}, the declaration of an instance states which view applies. 3387 Two primitives called \lstinline$up$ and \lstinline$down$ can be used to convert between the views. 3388 \item 3389 The Simula class \cite{Simula87} is essentially a record type. 3253 3390 Since the only operations on a record are member selection and assignment, which can not be overloaded, there is never any ambiguity as to whether the abstraction or the implementation view is being used. 3254 3391 In {\CC} 3255 \cite{ C++}, operations on class instances include assignment and ``\lstinline@&@'', which can be overloaded.3392 \cite{c++}, operations on class instances include assignment and ``\lstinline$&$'', which can be overloaded. 3256 3393 A ``scope resolution'' operator can be used inside the class to specify whether the abstract or implementation version of the operation should be used. 3257 3394 \item 3258 An Ada derived type definition \cite{ Ada} creates a new type from an old type, and also implicitly declares derived subprograms that correspond to the existing subprograms that use the old type as a parameter type or result type.3395 An Ada derived type definition \cite{ada} creates a new type from an old type, and also implicitly declares derived subprograms that correspond to the existing subprograms that use the old type as a parameter type or result type. 3259 3396 The derived subprograms are clones of the existing subprograms with the old type replaced by the derived type. 3260 3397 Literals and aggregates of the old type are also cloned. … … 3266 3403 In this case, explicit conversions between the derived type and the old type can be used. 3267 3404 \end{itemize} 3268 \CFA's rules are like Clu's, except that implicit conversions and conversion costs allow it to do away with most uses of \lstinline @up@ and \lstinline@down@.3405 \CFA's rules are like Clu's, except that implicit conversions and conversion costs allow it to do away with most uses of \lstinline$up$ and \lstinline$down$. 3269 3406 \end{rationale} 3270 3407 … … 3272 3409 \subsubsection{Default functions and objects} 3273 3410 3274 A declaration\index{type declaration} of a type identifier \lstinline @T@with type-class3275 \lstinline @type@implicitly declares a \define{default assignment} function3276 \lstinline @T ?=?( T *, T )@\use{?=?}, with the same \Index{scope} and \Index{linkage} as the identifier \lstinline@T@.3411 A declaration\index{type declaration} of a type identifier \lstinline$T$ with type-class 3412 \lstinline$type$ implicitly declares a \define{default assignment} function 3413 \lstinline$T ?=?( T *, T )$\use{?=?}, with the same \Index{scope} and \Index{linkage} as the identifier \lstinline$T$. 3277 3414 \begin{rationale} 3278 3415 Assignment is central to C's imperative programming style, and every existing C object type has assignment defined for it ( except for array types, which are treated as pointer types for purposes of assignment). 3279 3416 Without this rule, nearly every inferred type parameter would need an accompanying assignment assertion parameter. 3280 3417 If a type parameter should not have an assignment operation, 3281 \lstinline @dtype@should be used.3418 \lstinline$dtype$ should be used. 3282 3419 If a type should not have assignment defined, the user can define an assignment function that causes a run-time error, or provide an external declaration but no definition and thus cause a link-time error. 3283 3420 \end{rationale} 3284 3421 3285 A definition\index{type definition} of a type identifier \lstinline @T@ with \Index{implementation type} \lstinline@I@ and type-class \lstinline@type@implicitly defines a default assignment function.3286 A definition\index{type definition} of a type identifier \lstinline @T@ with implementation type \lstinline@I@and an assertion list implicitly defines \define{default function}s and3422 A definition\index{type definition} of a type identifier \lstinline$T$ with \Index{implementation type} \lstinline$I$ and type-class \lstinline$type$ implicitly defines a default assignment function. 3423 A definition\index{type definition} of a type identifier \lstinline$T$ with implementation type \lstinline$I$ and an assertion list implicitly defines \define{default function}s and 3287 3424 \define{default object}s as declared by the assertion declarations. 3288 The default objects and functions have the same \Index{scope} and \Index{linkage} as the identifier \lstinline @T@.3425 The default objects and functions have the same \Index{scope} and \Index{linkage} as the identifier \lstinline$T$. 3289 3426 Their values are determined as follows: 3290 3427 \begin{itemize} 3291 3428 \item 3292 If at the definition of \lstinline @T@ there is visible a declaration of an object with the same name as the default object, and if the type of that object with all occurrence of \lstinline@I@ replaced by \lstinline@T@is compatible with the type of the default object, then the default object is initialized with that object.3293 Otherwise the scope of the declaration of \lstinline @T@must contain a definition of the default object.3429 If at the definition of \lstinline$T$ there is visible a declaration of an object with the same name as the default object, and if the type of that object with all occurrence of \lstinline$I$ replaced by \lstinline$T$ is compatible with the type of the default object, then the default object is initialized with that object. 3430 Otherwise the scope of the declaration of \lstinline$T$ must contain a definition of the default object. 3294 3431 3295 3432 \item 3296 If at the definition of \lstinline @T@ there is visible a declaration of a function with the same name as the default function, and if the type of that function with all occurrence of \lstinline@I@ replaced by \lstinline@T@is compatible with the type of the default function, then the default function calls that function after converting its arguments and returns the converted result.3297 3298 Otherwise, if \lstinline @I@ contains exactly one anonymous member\index{anonymous member} such that at the definition of \lstinline@T@ there is visible a declaration of a function with the same name as the default function, and the type of that function with all occurrences of the anonymous member's type in its parameter list replaced by \lstinline@T@is compatible with the type of the default function, then the default function calls that function after converting its arguments and returns the result.3299 3300 Otherwise the scope of the declaration of \lstinline @T@must contain a definition of the default function.3433 If at the definition of \lstinline$T$ there is visible a declaration of a function with the same name as the default function, and if the type of that function with all occurrence of \lstinline$I$ replaced by \lstinline$T$ is compatible with the type of the default function, then the default function calls that function after converting its arguments and returns the converted result. 3434 3435 Otherwise, if \lstinline$I$ contains exactly one anonymous member\index{anonymous member} such that at the definition of \lstinline$T$ there is visible a declaration of a function with the same name as the default function, and the type of that function with all occurrences of the anonymous member's type in its parameter list replaced by \lstinline$T$ is compatible with the type of the default function, then the default function calls that function after converting its arguments and returns the result. 3436 3437 Otherwise the scope of the declaration of \lstinline$T$ must contain a definition of the default function. 3301 3438 \end{itemize} 3302 3439 \begin{rationale} … … 3304 3441 \end{rationale} 3305 3442 3306 A function or object with the same type and name as a default function or object that is declared within the scope of the definition of \lstinline @T@replaces the default function or object.3443 A function or object with the same type and name as a default function or object that is declared within the scope of the definition of \lstinline$T$ replaces the default function or object. 3307 3444 3308 3445 \examples … … 3314 3451 Pair b = { 1, 1 }; 3315 3452 \end{lstlisting} 3316 The definition of \lstinline @Pair@ implicitly defines two objects \lstinline@a@ and \lstinline@b@.3317 \lstinline @Pair a@ inherits its value from the \lstinline@struct impl a@.3453 The definition of \lstinline$Pair$ implicitly defines two objects \lstinline$a$ and \lstinline$b$. 3454 \lstinline$Pair a$ inherits its value from the \lstinline$struct impl a$. 3318 3455 The definition of 3319 \lstinline @Pair b@ is compulsory because there is no \lstinline@struct impl b@to construct a value from.3456 \lstinline$Pair b$ is compulsory because there is no \lstinline$struct impl b$ to construct a value from. 3320 3457 \begin{lstlisting} 3321 3458 trait ss( otype T ) { … … 3323 3460 void munge( T * ); 3324 3461 } 3325 otype Whatsit | ss( Whatsit ); §\use{Whatsit}§3326 otype Doodad | ss( Doodad ) = struct doodad { §\use{Doodad}§3462 otype Whatsit | ss( Whatsit );@\use{Whatsit}@ 3463 otype Doodad | ss( Doodad ) = struct doodad {@\use{Doodad}@ 3327 3464 Whatsit; // anonymous member 3328 3465 int extra; … … 3330 3467 Doodad clone( Doodad ) { ... } 3331 3468 \end{lstlisting} 3332 The definition of \lstinline @Doodad@implicitly defines three functions:3469 The definition of \lstinline$Doodad$ implicitly defines three functions: 3333 3470 \begin{lstlisting} 3334 3471 Doodad ?=?( Doodad *, Doodad ); … … 3336 3473 void munge( Doodad * ); 3337 3474 \end{lstlisting} 3338 The assignment function inherits \lstinline @struct doodad@'s assignment function because the types match when \lstinline@struct doodad@ is replaced by \lstinline@Doodad@throughout.3339 \lstinline @munge()@ inherits \lstinline@Whatsit@'s \lstinline@munge()@because the types match when3340 \lstinline @Whatsit@ is replaced by \lstinline@Doodad@ in the parameter list. \lstinline@clone()@ does \emph{not} inherit \lstinline@Whatsit@'s \lstinline@clone()@: replacement in the parameter list yields ``\lstinline@Whatsit clone( Doodad )@'', which is not compatible with3341 \lstinline @Doodad@'s \lstinline@clone()@'s type.3475 The assignment function inherits \lstinline$struct doodad$'s assignment function because the types match when \lstinline$struct doodad$ is replaced by \lstinline$Doodad$ throughout. 3476 \lstinline$munge()$ inherits \lstinline$Whatsit$'s \lstinline$munge()$ because the types match when 3477 \lstinline$Whatsit$ is replaced by \lstinline$Doodad$ in the parameter list. \lstinline$clone()$ does \emph{not} inherit \lstinline$Whatsit$'s \lstinline$clone()$: replacement in the parameter list yields ``\lstinline$Whatsit clone( Doodad )$'', which is not compatible with 3478 \lstinline$Doodad$'s \lstinline$clone()$'s type. 3342 3479 Hence the definition of 3343 ``\lstinline @Doodad clone( Doodad )@'' is necessary.3480 ``\lstinline$Doodad clone( Doodad )$'' is necessary. 3344 3481 3345 3482 Default functions and objects are subject to the normal scope rules. 3346 3483 \begin{lstlisting} 3347 otype T = §\ldots§;3348 T a_T = §\ldots§; // Default assignment used.3484 otype T = @\ldots@; 3485 T a_T = @\ldots@; // Default assignment used. 3349 3486 T ?=?( T *, T ); 3350 T a_T = §\ldots§; // Programmer-defined assignment called.3487 T a_T = @\ldots@; // Programmer-defined assignment called. 3351 3488 \end{lstlisting} 3352 3489 \begin{rationale} … … 3381 3518 \begin{syntax} 3382 3519 \oldlhs{labeled-statement} 3383 \rhs \lstinline @case@\nonterm{case-value-list} : \nonterm{statement}3520 \rhs \lstinline$case$ \nonterm{case-value-list} : \nonterm{statement} 3384 3521 \lhs{case-value-list} 3385 3522 \rhs \nonterm{case-value} 3386 \rhs \nonterm{case-value-list} \lstinline @,@\nonterm{case-value}3523 \rhs \nonterm{case-value-list} \lstinline$,$ \nonterm{case-value} 3387 3524 \lhs{case-value} 3388 3525 \rhs \nonterm{constant-expression} 3389 3526 \rhs \nonterm{subrange} 3390 3527 \lhs{subrange} 3391 \rhs \nonterm{constant-expression} \lstinline @~@\nonterm{constant-expression}3528 \rhs \nonterm{constant-expression} \lstinline$~$ \nonterm{constant-expression} 3392 3529 \end{syntax} 3393 3530 … … 3402 3539 case 1~4, 9~14, 27~32: 3403 3540 \end{lstlisting} 3404 The \lstinline @case@ and \lstinline@default@ clauses are restricted within the \lstinline@switch@ and \lstinline@choose@statements, precluding Duff's device.3541 The \lstinline$case$ and \lstinline$default$ clauses are restricted within the \lstinline$switch$ and \lstinline$choose$ statements, precluding Duff's device. 3405 3542 3406 3543 3407 3544 \subsection{Expression and null statements} 3408 3545 3409 The expression in an expression statement is treated as being cast to \lstinline @void@.3546 The expression in an expression statement is treated as being cast to \lstinline$void$. 3410 3547 3411 3548 … … 3414 3551 \begin{syntax} 3415 3552 \oldlhs{selection-statement} 3416 \rhs \lstinline @choose@ \lstinline@(@ \nonterm{expression} \lstinline@)@\nonterm{statement}3553 \rhs \lstinline$choose$ \lstinline$($ \nonterm{expression} \lstinline$)$ \nonterm{statement} 3417 3554 \end{syntax} 3418 3555 3419 The controlling expression \lstinline @E@ in the \lstinline@switch@ and \lstinline@choose@statement:3556 The controlling expression \lstinline$E$ in the \lstinline$switch$ and \lstinline$choose$ statement: 3420 3557 \begin{lstlisting} 3421 3558 switch ( E ) ... … … 3423 3560 \end{lstlisting} may have more than one interpretation, but it shall have only one interpretation with an integral type. 3424 3561 An \Index{integer promotion} is performed on the expression if necessary. 3425 The constant expressions in \lstinline @case@statements with the switch are converted to the promoted type.3562 The constant expressions in \lstinline$case$ statements with the switch are converted to the promoted type. 3426 3563 3427 3564 3428 3565 \setcounter{subsubsection}{3} 3429 \subsubsection [The choose statement]{The \lstinline@choose@statement}3430 3431 The \lstinline @choose@ statement is the same as the \lstinline@switch@ statement except control transfers to the end of the \lstinline@choose@ statement at a \lstinline@case@ or \lstinline@default@labeled statement.3432 The \lstinline @fallthru@ statement is used to fall through to the next \lstinline@case@ or \lstinline@default@labeled statement.3566 \subsubsection{The \lstinline$choose$ statement} 3567 3568 The \lstinline$choose$ statement is the same as the \lstinline$switch$ statement except control transfers to the end of the \lstinline$choose$ statement at a \lstinline$case$ or \lstinline$default$ labeled statement. 3569 The \lstinline$fallthru$ statement is used to fall through to the next \lstinline$case$ or \lstinline$default$ labeled statement. 3433 3570 The following have identical meaning: 3434 3571 \begin{flushleft} … … 3455 3592 \end{tabular} 3456 3593 \end{flushleft} 3457 The \lstinline @choose@ statement addresses the problem of accidental fall-through associated with the \lstinline@switch@statement.3594 The \lstinline$choose$ statement addresses the problem of accidental fall-through associated with the \lstinline$switch$ statement. 3458 3595 3459 3596 3460 3597 \subsection{Iteration statements} 3461 3598 3462 The controlling expression \lstinline @E@in the loops3599 The controlling expression \lstinline$E$ in the loops 3463 3600 \begin{lstlisting} 3464 3601 if ( E ) ... 3465 3602 while ( E ) ... 3466 3603 do ... while ( E ); 3467 \end{lstlisting} is treated as ``\lstinline @( int )((E)!=0)@''.3604 \end{lstlisting} is treated as ``\lstinline$( int )((E)!=0)$''. 3468 3605 3469 3606 The statement 3470 3607 \begin{lstlisting} 3471 for ( a; b; c ) §\ldots§3608 for ( a; b; c ) @\ldots@ 3472 3609 \end{lstlisting} is treated as 3473 3610 \begin{lstlisting} … … 3480 3617 \begin{syntax} 3481 3618 \oldlhs{jump-statement} 3482 \rhs \lstinline @continue@\nonterm{identifier}\opt3483 \rhs \lstinline @break@\nonterm{identifier}\opt3619 \rhs \lstinline$continue$ \nonterm{identifier}\opt 3620 \rhs \lstinline$break$ \nonterm{identifier}\opt 3484 3621 \rhs \ldots 3485 \rhs \lstinline @throw@\nonterm{assignment-expression}\opt3486 \rhs \lstinline @throwResume@\nonterm{assignment-expression}\opt \nonterm{at-expression}\opt3487 \lhs{at-expression} \lstinline @_At@\nonterm{assignment-expression}3622 \rhs \lstinline$throw$ \nonterm{assignment-expression}\opt 3623 \rhs \lstinline$throwResume$ \nonterm{assignment-expression}\opt \nonterm{at-expression}\opt 3624 \lhs{at-expression} \lstinline$_At$ \nonterm{assignment-expression} 3488 3625 \end{syntax} 3489 3626 3490 Labeled \lstinline @continue@ and \lstinline@break@ allow useful but restricted control-flow that reduces the need for the \lstinline@goto@statement for exiting multiple nested control-structures.3627 Labeled \lstinline$continue$ and \lstinline$break$ allow useful but restricted control-flow that reduces the need for the \lstinline$goto$ statement for exiting multiple nested control-structures. 3491 3628 \begin{lstlisting} 3492 3629 L1: { // compound … … 3515 3652 3516 3653 \setcounter{subsubsection}{1} 3517 \subsubsection [The continue statement]{The \lstinline@continue@statement}3518 3519 The identifier in a \lstinline @continue@statement shall name a label located on an enclosing iteration statement.3520 3521 3522 \subsubsection [The break statement]{The \lstinline@break@statement}3523 3524 The identifier in a \lstinline @break@statement shall name a label located on an enclosing compound, selection or iteration statement.3525 3526 3527 \subsubsection [The return statement]{The \lstinline@return@statement}3528 3529 An expression in a \lstinline @return@statement is treated as being cast to the result type of the function.3530 3531 3532 \subsubsection [The throw statement]{The \lstinline@throw@statement}3654 \subsubsection{The \lstinline$continue$ statement} 3655 3656 The identifier in a \lstinline$continue$ statement shall name a label located on an enclosing iteration statement. 3657 3658 3659 \subsubsection{The \lstinline$break$ statement} 3660 3661 The identifier in a \lstinline$break$ statement shall name a label located on an enclosing compound, selection or iteration statement. 3662 3663 3664 \subsubsection{The \lstinline$return$ statement} 3665 3666 An expression in a \lstinline$return$ statement is treated as being cast to the result type of the function. 3667 3668 3669 \subsubsection{The \lstinline$throw$ statement} 3533 3670 3534 3671 When an exception is raised, \Index{propagation} directs control from a raise in the source execution to a handler in the faulting execution. 3535 3672 3536 3673 3537 \subsubsection [The throwResume statement]{The \lstinline@throwResume@statement}3674 \subsubsection{The \lstinline$throwResume$ statement} 3538 3675 3539 3676 … … 3542 3679 \begin{syntax} 3543 3680 \lhs{exception-statement} 3544 \rhs \lstinline @try@\nonterm{compound-statement} \nonterm{handler-list}3545 \rhs \lstinline @try@\nonterm{compound-statement} \nonterm{finally-clause}3546 \rhs \lstinline @try@\nonterm{compound-statement} \nonterm{handler-list} \nonterm{finally-clause}3681 \rhs \lstinline$try$ \nonterm{compound-statement} \nonterm{handler-list} 3682 \rhs \lstinline$try$ \nonterm{compound-statement} \nonterm{finally-clause} 3683 \rhs \lstinline$try$ \nonterm{compound-statement} \nonterm{handler-list} \nonterm{finally-clause} 3547 3684 \lhs{handler-list} 3548 3685 \rhs \nonterm{handler-clause} 3549 \rhs \lstinline @catch@ \lstinline@(@ \ldots \lstinline@)@\nonterm{compound-statement}3550 \rhs \nonterm{handler-clause} \lstinline @catch@ \lstinline@(@ \ldots \lstinline@)@\nonterm{compound-statement}3551 \rhs \lstinline @catchResume@ \lstinline@(@ \ldots \lstinline@)@\nonterm{compound-statement}3552 \rhs \nonterm{handler-clause} \lstinline @catchResume@ \lstinline@(@ \ldots \lstinline@)@\nonterm{compound-statement}3686 \rhs \lstinline$catch$ \lstinline$($ \ldots \lstinline$)$ \nonterm{compound-statement} 3687 \rhs \nonterm{handler-clause} \lstinline$catch$ \lstinline$($ \ldots \lstinline$)$ \nonterm{compound-statement} 3688 \rhs \lstinline$catchResume$ \lstinline$($ \ldots \lstinline$)$ \nonterm{compound-statement} 3689 \rhs \nonterm{handler-clause} \lstinline$catchResume$ \lstinline$($ \ldots \lstinline$)$ \nonterm{compound-statement} 3553 3690 \lhs{handler-clause} 3554 \rhs \lstinline @catch@ \lstinline@(@ \nonterm{exception-declaration} \lstinline@)@\nonterm{compound-statement}3555 \rhs \nonterm{handler-clause} \lstinline @catch@ \lstinline@(@ \nonterm{exception-declaration} \lstinline@)@\nonterm{compound-statement}3556 \rhs \lstinline @catchResume@ \lstinline@(@ \nonterm{exception-declaration} \lstinline@)@\nonterm{compound-statement}3557 \rhs \nonterm{handler-clause} \lstinline @catchResume@ \lstinline@(@ \nonterm{exception-declaration} \lstinline@)@\nonterm{compound-statement}3691 \rhs \lstinline$catch$ \lstinline$($ \nonterm{exception-declaration} \lstinline$)$ \nonterm{compound-statement} 3692 \rhs \nonterm{handler-clause} \lstinline$catch$ \lstinline$($ \nonterm{exception-declaration} \lstinline$)$ \nonterm{compound-statement} 3693 \rhs \lstinline$catchResume$ \lstinline$($ \nonterm{exception-declaration} \lstinline$)$ \nonterm{compound-statement} 3694 \rhs \nonterm{handler-clause} \lstinline$catchResume$ \lstinline$($ \nonterm{exception-declaration} \lstinline$)$ \nonterm{compound-statement} 3558 3695 \lhs{finally-clause} 3559 \rhs \lstinline @finally@\nonterm{compound-statement}3696 \rhs \lstinline$finally$ \nonterm{compound-statement} 3560 3697 \lhs{exception-declaration} 3561 3698 \rhs \nonterm{type-specifier} … … 3565 3702 \rhs \nonterm{new-abstract-declarator-tuple} 3566 3703 \lhs{asynchronous-statement} 3567 \rhs \lstinline @enable@\nonterm{identifier-list} \nonterm{compound-statement}3568 \rhs \lstinline @disable@\nonterm{identifier-list} \nonterm{compound-statement}3704 \rhs \lstinline$enable$ \nonterm{identifier-list} \nonterm{compound-statement} 3705 \rhs \lstinline$disable$ \nonterm{identifier-list} \nonterm{compound-statement} 3569 3706 \end{syntax} 3570 3707 … … 3572 3709 3573 3710 3574 \subsubsection [The try statement]{The \lstinline@try@statement}3575 3576 The \lstinline @try@statement is a block with associated handlers, called a \Index{guarded block};3711 \subsubsection{The \lstinline$try$ statement} 3712 3713 The \lstinline$try$ statement is a block with associated handlers, called a \Index{guarded block}; 3577 3714 all other blocks are \Index{unguarded block}s. 3578 A \lstinline @goto@, \lstinline@break@, \lstinline@return@, or \lstinline@continue@statement can be used to transfer control out of a try block or handler, but not into one.3579 3580 3581 \subsubsection [The enable/disable statements]{The \lstinline@enable@/\lstinline@disable@statements}3582 3583 The \lstinline @enable@/\lstinline@disable@statements toggle delivery of \Index{asynchronous exception}s.3715 A \lstinline$goto$, \lstinline$break$, \lstinline$return$, or \lstinline$continue$ statement can be used to transfer control out of a try block or handler, but not into one. 3716 3717 3718 \subsubsection{The \lstinline$enable$/\lstinline$disable$ statements} 3719 3720 The \lstinline$enable$/\lstinline$disable$ statements toggle delivery of \Index{asynchronous exception}s. 3584 3721 3585 3722 … … 3591 3728 \subsection{Predefined macro names} 3592 3729 3593 The implementation shall define the macro names \lstinline @__LINE__@, \lstinline@__FILE__@,3594 \lstinline @__DATE__@, and \lstinline@__TIME__@, as in the {\c11} standard.3595 It shall not define the macro name \lstinline @__STDC__@.3596 3597 In addition, the implementation shall define the macro name \lstinline @__CFORALL__@to be the decimal constant 1.3730 The implementation shall define the macro names \lstinline$__LINE__$, \lstinline$__FILE__$, 3731 \lstinline$__DATE__$, and \lstinline$__TIME__$, as in the {\c11} standard. 3732 It shall not define the macro name \lstinline$__STDC__$. 3733 3734 In addition, the implementation shall define the macro name \lstinline$__CFORALL__$ to be the decimal constant 1. 3598 3735 3599 3736 … … 3612 3749 The pointer, integral, and floating-point types are all \define{scalar types}. 3613 3750 All of these types can be logically negated and compared. 3614 The assertion ``\lstinline @scalar( Complex )@'' should be read as ``type \lstinline@Complex@is scalar''.3615 \begin{lstlisting} 3616 trait scalar( otype T ) { §\impl{scalar}§3751 The assertion ``\lstinline$scalar( Complex )$'' should be read as ``type \lstinline$Complex$ is scalar''. 3752 \begin{lstlisting} 3753 trait scalar( otype T ) {@\impl{scalar}@ 3617 3754 int !?( T ); 3618 3755 int ?<?( T, T ), ?<=?( T, T ), ?==?( T, T ), ?>=?( T, T ), ?>?( T, T ), ?!=?( T, T ); … … 3624 3761 This is equivalent to inheritance of specifications. 3625 3762 \begin{lstlisting} 3626 trait arithmetic( otype T | scalar( T ) ) { §\impl{arithmetic}§§\use{scalar}§3763 trait arithmetic( otype T | scalar( T ) ) {@\impl{arithmetic}@@\use{scalar}@ 3627 3764 T +?( T ), -?( T ); 3628 3765 T ?*?( T, T ), ?/?( T, T ), ?+?( T, T ), ?-?( T, T ); … … 3630 3767 \end{lstlisting} 3631 3768 3632 The various flavors of \lstinline @char@ and \lstinline@int@and the enumerated types make up the3769 The various flavors of \lstinline$char$ and \lstinline$int$ and the enumerated types make up the 3633 3770 \define{integral types}. 3634 3771 \begin{lstlisting} 3635 trait integral( otype T | arithmetic( T ) ) { §\impl{integral}§§\use{arithmetic}§3772 trait integral( otype T | arithmetic( T ) ) {@\impl{integral}@@\use{arithmetic}@ 3636 3773 T ~?( T ); 3637 3774 T ?&?( T, T ), ?|?( T, T ), ?^?( T, T ); … … 3647 3784 The only operation that can be applied to all modifiable lvalues is simple assignment. 3648 3785 \begin{lstlisting} 3649 trait m_lvalue( otype T ) { §\impl{m_lvalue}§3786 trait m_lvalue( otype T ) {@\impl{m_lvalue}@ 3650 3787 T ?=?( T *, T ); 3651 3788 }; … … 3657 3794 Scalars can also be incremented and decremented. 3658 3795 \begin{lstlisting} 3659 trait m_l_scalar( otype T | scalar( T ) | m_lvalue( T ) ) { §\impl{m_l_scalar}§3660 T ?++( T * ), ?--( T * ); §\use{scalar}§§\use{m_lvalue}§3796 trait m_l_scalar( otype T | scalar( T ) | m_lvalue( T ) ) {@\impl{m_l_scalar}@ 3797 T ?++( T * ), ?--( T * );@\use{scalar}@@\use{m_lvalue}@ 3661 3798 T ++?( T * ), --?( T * ); 3662 3799 }; … … 3664 3801 3665 3802 Modifiable arithmetic lvalues are both modifiable scalar lvalues and arithmetic. 3666 Note that this results in the ``inheritance'' of \lstinline @scalar@along both paths.3667 \begin{lstlisting} 3668 trait m_l_arithmetic( otype T | m_l_scalar( T ) | arithmetic( T ) ) { §\impl{m_l_arithmetic}§3669 T ?/=?( T *, T ), ?*=?( T *, T ); §\use{m_l_scalar}§§\use{arithmetic}§3803 Note that this results in the ``inheritance'' of \lstinline$scalar$ along both paths. 3804 \begin{lstlisting} 3805 trait m_l_arithmetic( otype T | m_l_scalar( T ) | arithmetic( T ) ) {@\impl{m_l_arithmetic}@ 3806 T ?/=?( T *, T ), ?*=?( T *, T );@\use{m_l_scalar}@@\use{arithmetic}@ 3670 3807 T ?+=?( T *, T ), ?-=?( T *, T ); 3671 3808 }; 3672 trait m_l_integral( otype T | m_l_arithmetic( T ) | integral( T ) ) { §\impl{m_l_integral}§3673 T ?&=?( T *, T ), ?|=?( T *, T ), ?^=?( T *, T ); §\use{m_l_arithmetic}§3674 T ?%=?( T *, T ), ?<<=?( T *, T ), ?>>=?( T *, T ); §\use{integral}§3809 trait m_l_integral( otype T | m_l_arithmetic( T ) | integral( T ) ) {@\impl{m_l_integral}@ 3810 T ?&=?( T *, T ), ?|=?( T *, T ), ?^=?( T *, T );@\use{m_l_arithmetic}@ 3811 T ?%=?( T *, T ), ?<<=?( T *, T ), ?>>=?( T *, T );@\use{integral}@ 3675 3812 }; 3676 3813 \end{lstlisting} … … 3680 3817 3681 3818 Array types can barely be said to exist in {\c11}, since in most cases an array name is treated as a constant pointer to the first element of the array, and the subscript expression 3682 ``\lstinline @a[i]@'' is equivalent to the dereferencing expression ``\lstinline@(*( a+( i )))@''.3683 Technically, pointer arithmetic and pointer comparisons other than ``\lstinline @==@'' and3684 ``\lstinline @!=@'' are only defined for pointers to array elements, but the type system does not enforce those restrictions.3819 ``\lstinline$a[i]$'' is equivalent to the dereferencing expression ``\lstinline$(*( a+( i )))$''. 3820 Technically, pointer arithmetic and pointer comparisons other than ``\lstinline$==$'' and 3821 ``\lstinline$!=$'' are only defined for pointers to array elements, but the type system does not enforce those restrictions. 3685 3822 Consequently, there is no need for a separate ``array type'' specification. 3686 3823 3687 3824 Pointer types are scalar types. 3688 Like other scalar types, they have ``\lstinline @+@'' and3689 ``\lstinline @-@'' operators, but the types do not match the types of the operations in3690 \lstinline @arithmetic@, so these operators cannot be consolidated in \lstinline@scalar@.3691 \begin{lstlisting} 3692 trait pointer( type P | scalar( P ) ) { §\impl{pointer}§§\use{scalar}§3825 Like other scalar types, they have ``\lstinline$+$'' and 3826 ``\lstinline$-$'' operators, but the types do not match the types of the operations in 3827 \lstinline$arithmetic$, so these operators cannot be consolidated in \lstinline$scalar$. 3828 \begin{lstlisting} 3829 trait pointer( type P | scalar( P ) ) {@\impl{pointer}@@\use{scalar}@ 3693 3830 P ?+?( P, long int ), ?+?( long int, P ), ?-?( P, long int ); 3694 3831 ptrdiff_t ?-?( P, P ); 3695 3832 }; 3696 trait m_l_pointer( type P | pointer( P ) | m_l_scalar( P ) ) { §\impl{m_l_pointer}§3833 trait m_l_pointer( type P | pointer( P ) | m_l_scalar( P ) ) {@\impl{m_l_pointer}@ 3697 3834 P ?+=?( P *, long int ), ?-=?( P *, long int ); 3698 3835 P ?=?( P *, void * ); … … 3703 3840 Specifications that define the dereference operator ( or subscript operator ) require two parameters, one for the pointer type and one for the pointed-at ( or element ) type. 3704 3841 Different specifications are needed for each set of \Index{type qualifier}s, because qualifiers are not included in types. 3705 The assertion ``\lstinline @|ptr_to( Safe_pointer, int )@'' should be read as3706 ``\lstinline @Safe_pointer@ acts like a pointer to \lstinline@int@''.3707 \begin{lstlisting} 3708 trait ptr_to( otype P | pointer( P ), otype T ) {§\impl{ptr_to}§§\use{pointer}§3842 The assertion ``\lstinline$|ptr_to( Safe_pointer, int )$'' should be read as 3843 ``\lstinline$Safe_pointer$ acts like a pointer to \lstinline$int$''. 3844 \begin{lstlisting} 3845 trait ptr_to( type P | pointer( P ), otype T ) {@\impl{ptr_to}@@\use{pointer}@ 3709 3846 lvalue T *?( P ); 3710 3847 lvalue T ?[?]( P, long int ); 3711 3848 }; 3712 trait ptr_to_const( otype P | pointer( P ), otype T ) {§\impl{ptr_to_const}§3849 trait ptr_to_const( type P | pointer( P ), otype T ) {@\impl{ptr_to_const}@ 3713 3850 const lvalue T *?( P ); 3714 const lvalue T ?[?]( P, long int ); §\use{pointer}§3851 const lvalue T ?[?]( P, long int );@\use{pointer}@ 3715 3852 }; 3716 trait ptr_to_volatile( otype P | pointer( P ), otype T ) }§\impl{ptr_to_volatile}§3853 trait ptr_to_volatile( type P | pointer( P ), otype T ) }@\impl{ptr_to_volatile}@ 3717 3854 volatile lvalue T *?( P ); 3718 volatile lvalue T ?[?]( P, long int ); §\use{pointer}§3855 volatile lvalue T ?[?]( P, long int );@\use{pointer}@ 3719 3856 }; 3720 trait ptr_to_const_volatile( otype P | pointer( P ), otype T ) }§\impl{ptr_to_const_volatile}§3721 const volatile lvalue T *?( P ); §\use{pointer}§3857 trait ptr_to_const_volatile( type P | pointer( P ), otype T ) }@\impl{ptr_to_const_volatile}@ 3858 const volatile lvalue T *?( P );@\use{pointer}@ 3722 3859 const volatile lvalue T ?[?]( P, long int ); 3723 3860 }; 3724 3861 \end{lstlisting} 3725 3862 3726 Assignment to pointers is more complicated than is the case with other types, because the target's type can have extra type qualifiers in the pointed-at type: a ``\lstinline @T *@'' can be assigned to a ``\lstinline@const T *@'', a ``\lstinline@volatile T *@'', and a ``\lstinline@const volatile T *@''.3863 Assignment to pointers is more complicated than is the case with other types, because the target's type can have extra type qualifiers in the pointed-at type: a ``\lstinline$T *$'' can be assigned to a ``\lstinline$const T *$'', a ``\lstinline$volatile T *$'', and a ``\lstinline$const volatile T *$''. 3727 3864 Again, the pointed-at type is passed in, so that assertions can connect these specifications to the 3728 ``\lstinline @ptr_to@'' specifications.3729 \begin{lstlisting} 3730 trait m_l_ptr_to( otype P | m_l_pointer( P ),§\use{m_l_pointer}§§\impl{m_l_ptr_to}§ otype T | ptr_to( P, T )§\use{ptr_to}§{3865 ``\lstinline$ptr_to$'' specifications. 3866 \begin{lstlisting} 3867 trait m_l_ptr_to( type P | m_l_pointer( P ),@\use{m_l_pointer}@@\impl{m_l_ptr_to}@ otype T | ptr_to( P, T )@\use{ptr_to}@ { 3731 3868 P ?=?( P *, T * ); 3732 3869 T * ?=?( T **, P ); 3733 3870 }; 3734 trait m_l_ptr_to_const( otype P | m_l_pointer( P ),§\use{m_l_pointer}§§\impl{m_l_ptr_to_const}§ otype T | ptr_to_const( P, T )§\use{ptr_to_const}§) {3871 trait m_l_ptr_to_const( type P | m_l_pointer( P ),@\use{m_l_pointer}@@\impl{m_l_ptr_to_const}@ otype T | ptr_to_const( P, T )@\use{ptr_to_const}@) { 3735 3872 P ?=?( P *, const T * ); 3736 3873 const T * ?=?( const T **, P ); 3737 3874 }; 3738 trait m_l_ptr_to_volatile( otype P | m_l_pointer( P ),§\use{m_l_pointer}§§\impl{m_l_ptr_to_volatile}§ otype T | ptr_to_volatile( P, T )) {§\use{ptr_to_volatile}§3875 trait m_l_ptr_to_volatile( type P | m_l_pointer( P ),@\use{m_l_pointer}@@\impl{m_l_ptr_to_volatile}@ otype T | ptr_to_volatile( P, T )) {@\use{ptr_to_volatile}@ 3739 3876 P ?=?( P *, volatile T * ); 3740 3877 volatile T * ?=?( volatile T **, P ); 3741 3878 }; 3742 trait m_l_ptr_to_const_volatile( otype P | ptr_to_const_volatile( P ),§\use{ptr_to_const_volatile}§§\impl{m_l_ptr_to_const_volatile}§3743 otype T | m_l_ptr_to_volatile( P, T ) | m_l_ptr_to_const( P )) {§\use{m_l_ptr_to_const}§§\use{m_l_ptr_to_volatile}§3879 trait m_l_ptr_to_const_volatile( type P | ptr_to_const_volatile( P ),@\use{ptr_to_const_volatile}@@\impl{m_l_ptr_to_const_volatile}@ 3880 type T | m_l_ptr_to_volatile( P, T ) | m_l_ptr_to_const( P )) {@\use{m_l_ptr_to_const}@@\use{m_l_ptr_to_volatile}@ 3744 3881 P ?=?( P *, const volatile T * ); 3745 3882 const volatile T * ?=?( const volatile T **, P ); … … 3750 3887 An alternative specification can make use of the fact that qualification of the pointed-at type is part of a pointer type to capture that regularity. 3751 3888 \begin{lstlisting} 3752 trait m_l_ptr_like( type MyP | m_l_pointer( MyP ), §\use{m_l_pointer}§§\impl{m_l_ptr_like}§type CP | m_l_pointer( CP ) ) {3889 trait m_l_ptr_like( type MyP | m_l_pointer( MyP ),@\use{m_l_pointer}@@\impl{m_l_ptr_like}@ type CP | m_l_pointer( CP ) ) { 3753 3890 MyP ?=?( MyP *, CP ); 3754 3891 CP ?=?( CP *, MyP ); 3755 3892 }; 3756 3893 \end{lstlisting} 3757 The assertion ``\lstinline @| m_l_ptr_like( Safe_ptr, const int * )@'' should be read as3758 ``\lstinline @Safe_ptr@ is a pointer type like \lstinline@const int *@''.3894 The assertion ``\lstinline$| m_l_ptr_like( Safe_ptr, const int * )$'' should be read as 3895 ``\lstinline$Safe_ptr$ is a pointer type like \lstinline$const int *$''. 3759 3896 This specification has two defects, compared to the original four: there is no automatic assertion that dereferencing a 3760 \lstinline @MyP@ produces an lvalue of the type that \lstinline@CP@points at, and the3761 ``\lstinline @|m_l_pointer( CP )@'' assertion provides only a weak assurance that the argument passed to \lstinline@CP@really is a pointer type.3897 \lstinline$MyP$ produces an lvalue of the type that \lstinline$CP$ points at, and the 3898 ``\lstinline$|m_l_pointer( CP )$'' assertion provides only a weak assurance that the argument passed to \lstinline$CP$ really is a pointer type. 3762 3899 3763 3900 … … 3765 3902 3766 3903 Different operators often have related meanings; 3767 for instance, in C, ``\lstinline @+@'',3768 ``\lstinline @+=@'', and the two versions of ``\lstinline@++@'' perform variations of addition.3904 for instance, in C, ``\lstinline$+$'', 3905 ``\lstinline$+=$'', and the two versions of ``\lstinline$++$'' perform variations of addition. 3769 3906 Languages like {\CC} and Ada allow programmers to define operators for new types, but do not require that these relationships be preserved, or even that all of the operators be implemented. 3770 3907 Completeness and consistency is left to the good taste and discretion of the programmer. … … 3779 3916 The different comparison operators have obvious relationships, but there is no obvious subset of the operations to use in the implementation of the others. 3780 3917 However, it is usually convenient to implement a single comparison function that returns a negative integer, 0, or a positive integer if its first argument is respectively less than, equal to, or greater than its second argument; 3781 the library function \lstinline @strcmp@is an example.3782 3783 C and \CFA have an extra, non-obvious comparison operator: ``\lstinline @!@'', logical negation, returns 1 if its operand compares equal to 0, and 0 otherwise.3918 the library function \lstinline$strcmp$ is an example. 3919 3920 C and \CFA have an extra, non-obvious comparison operator: ``\lstinline$!$'', logical negation, returns 1 if its operand compares equal to 0, and 0 otherwise. 3784 3921 \begin{lstlisting} 3785 3922 trait comparable( otype T ) { … … 3830 3967 3831 3968 Note that, although an arithmetic type would certainly provide comparison functions, and an integral type would provide arithmetic operations, there does not have to be any relationship among 3832 \lstinline @int_base@, \lstinline@arith_base@ and \lstinline@comparable@.3969 \lstinline$int_base$, \lstinline$arith_base$ and \lstinline$comparable$. 3833 3970 Note also that these declarations provide guidance and assistance, but they do not define an absolutely minimal set of requirements. 3834 A truly minimal implementation of an arithmetic type might only provide \lstinline@0@, \lstinline@1@, and \lstinline@?-=?@, which would be used by polymorphic \lstinline@?+=?@, \lstinline@?*=?@, and \lstinline@?/=?@ functions. 3835 3836 Note also that \lstinline@short@ is an integer type in C11 terms, but has no operations! 3971 A truly minimal implementation of an arithmetic type might only provide 3972 \lstinline$0$, \lstinline$1$, and \lstinline$?-=?$, which would be used by polymorphic 3973 \lstinline$?+=?$, \lstinline$?*=?$, and \lstinline$?/=?$ functions. 3974 3975 Note also that \lstinline$short$ is an integer type in C11 terms, but has no operations! 3837 3976 3838 3977 … … 3841 3980 3842 3981 Restrict allowed to qualify anything, or type/dtype parameters, but only affects pointers. 3843 This gets into \lstinline @noalias@territory.3844 Qualifying anything (``\lstinline @short restrict rs@'') means pointer parameters of \lstinline@?++@, etc, would need restrict qualifiers.3982 This gets into \lstinline$noalias$ territory. 3983 Qualifying anything (``\lstinline$short restrict rs$'') means pointer parameters of \lstinline$?++$, etc, would need restrict qualifiers. 3845 3984 3846 3985 Enumerated types. … … 3852 3991 Color, enum Color ) really make sense? ?++ does, but it adds (int)1. 3853 3992 3854 Operators on {,signed,unsigned} char and other small types. \lstinline@?<?@harmless;3993 Operators on {,signed,unsigned} char and other small types. ?<? harmless; 3855 3994 ?*? questionable for chars. 3856 3995 Generic selections make these choices visible. … … 3858 3997 ``promotion'' function? 3859 3998 3860 \lstinline @register@assignment might be handled as assignment to a temporary with copying back and forth, but copying must not be done by assignment.3861 3862 Don't use \lstinline@ptrdiff_t@by name in the predefineds.3999 \lstinline$register$ assignment might be handled as assignment to a temporary with copying back and forth, but copying must not be done by assignment. 4000 4001 Don't use ptrdiff\_t by name in the predefineds. 3863 4002 3864 4003 Polymorphic objects. … … 3867 4006 3868 4007 \bibliographystyle{plain} 3869 \bibliography{ cfa}4008 \bibliography{refrat} 3870 4009 3871 4010
Note:
See TracChangeset
for help on using the changeset viewer.