source: doc/refrat/refrat.tex @ 83e680d

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 83e680d was 83e680d, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

change to 11pt, add DRAFT watermark, share new keyword-list

  • Property mode set to 100644
File size: 188.1 KB
Line 
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%%
3%% Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
4%%
5%% The contents of this file are covered under the licence agreement in the
6%% file "LICENCE" distributed with Cforall.
7%%
8%% refrat.tex --
9%%
10%% Author           : Peter A. Buhr
11%% Created On       : Wed Apr  6 14:52:25 2016
12%% Last Modified By : Peter A. Buhr
13%% Last Modified On : Sun Aug  6 08:53:08 2017
14%% Update Count     : 99
15%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16
17% requires tex packages: texlive-base texlive-latex-base tex-common texlive-humanities texlive-latex-extra texlive-fonts-recommended
18
19\documentclass[openright,twoside,11pt]{report}
20
21%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22
23% Latex packages used in the document.
24\usepackage[T1]{fontenc}                                % allow Latin1 (extended ASCII) characters
25\usepackage{textcomp}
26\usepackage[latin1]{inputenc}
27
28\usepackage{fullpage,times,comment}
29\usepackage{epic,eepic}
30\usepackage{upquote}                                                                    % switch curled `'" to straight
31\usepackage{calc}
32\usepackage{xspace}
33\usepackage{varioref}                                                                   % extended references
34\usepackage{listings}                                                                   % format program code
35\usepackage[flushmargin]{footmisc}                                              % support label/reference in footnote
36\usepackage{latexsym}                                   % \Box glyph
37\usepackage{mathptmx}                                   % better math font with "times"
38\usepackage[usenames]{color}
39\input{common}                                          % common CFA document macros
40\usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
41\usepackage{breakurl}
42\renewcommand{\UrlFont}{\small\sf}
43
44\usepackage[pagewise]{lineno}
45\renewcommand{\linenumberfont}{\scriptsize\sffamily}
46\usepackage[firstpage]{draftwatermark}
47\SetWatermarkLightness{0.9}
48
49% Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore
50% removes it as a variable-name character so keywords in variables are highlighted. MUST APPEAR
51% AFTER HYPERREF.
52\renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
53
54\setlength{\topmargin}{-0.45in}                                                 % move running title into header
55\setlength{\headsep}{0.25in}
56
57%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58
59\CFAStyle                                                                                               % use default CFA format-style
60\lstnewenvironment{C++}[1][]                            % use C++ style
61{\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®}#1}}
62{}
63
64% inline code ©...© (copyright symbol) emacs: C-q M-)
65% red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
66% blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
67% green highlighting ¢...¢ (cent symbol) emacs: C-q M-"
68% LaTex escape §...§ (section symbol) emacs: C-q M-'
69% keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^
70% math escape $...$ (dollar symbol)
71
72%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73
74% Names used in the document.
75\newcommand{\Version}{\input{../../version}}
76\newcommand{\Textbf}[2][red]{{\color{#1}{\textbf{#2}}}}
77\newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}}
78\newcommand{\R}[1]{\Textbf{#1}}
79\newcommand{\B}[1]{{\Textbf[blue]{#1}}}
80\newcommand{\G}[1]{{\Textbf[OliveGreen]{#1}}}
81
82%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
84\setcounter{secnumdepth}{3}                             % number subsubsections
85\setcounter{tocdepth}{3}                                % subsubsections in table of contents
86\makeindex
87
88%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89
90\title{\Huge
91\vspace*{1in}
92\CFA (\CFL) Reference Manual and Rationale
93}% title
94
95\author{\huge
96Glen Ditchfield and Peter A. Buhr
97}% author
98
99\date{
100\today
101}% date
102
103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104
105\begin{document}
106\pagestyle{headings}
107% changed after setting pagestyle
108\renewcommand{\chaptermark}[1]{\markboth{\thechapter\quad #1}{\thechapter\quad #1}}
109\renewcommand{\sectionmark}[1]{\markboth{\thesection\quad #1}{\thesection\quad #1}}
110\renewcommand{\subsectionmark}[1]{\markboth{\thesubsection\quad #1}{\thesubsection\quad #1}}
111\pagenumbering{roman}
112\linenumbers                                            % comment out to turn off line numbering
113
114\maketitle
115\thispagestyle{empty}
116\vspace*{\fill}
117\noindent
118\copyright\,2015 Glen Ditchfield \\ \\
119\noindent
120This work is licensed under the Creative Commons Attribution 4.0 International License.
121To view a copy of this license, visit {\small\url{http://creativecommons.org/licenses/by/4.0}}.
122\vspace*{1in}
123
124\clearpage
125\thispagestyle{plain}
126\pdfbookmark[1]{Contents}{section}
127\tableofcontents
128
129\clearpage
130\thispagestyle{plain}
131\pagenumbering{arabic}
132
133
134\chapter*{Introduction}\addcontentsline{toc}{chapter}{Introduction}
135
136This document is a reference manual and rationale for \CFA, a polymorphic extension of the C programming language.
137It covers low-level syntactic and semantic details of the language to address complex language issues for programmers, and provide language implementers with a precise language description.
138It makes frequent reference to the \Celeven standard~\cite{C11}, and occasionally compares \CFA to \CC~\cite{C++}.
139Changes to the syntax and additional features are expected to be included in later revisions.
140
141The manual deliberately imitates the ordering of the \Celeven standard (although the section numbering differs).
142Unfortunately, this means the manual contains more ``forward references'' than usual, making it harder to follow if the reader does not have a copy of the \Celeven standard.
143For a simple introduction to \CFA, see the companion document ``An Overview of \CFA''
144\cite{Ditchfield96:Overview}.
145
146\begin{rationale}
147Commentary (like this) is quoted with quads.
148Commentary usually deals with subtle points, the rationale behind a rule, and design decisions.
149\end{rationale}
150
151% No ``Scope'' or ``Normative references'' chapters yet.
152
153
154\setcounter{chapter}{2}
155\chapter{Terms, definitions, and symbols}
156
157Terms from the \Celeven standard used in this document have the same meaning as in the \Celeven standard.
158
159% No ``Conformance'' or ``Environment'' chapters yet.
160
161
162\setcounter{chapter}{5}
163\chapter{Language}
164
165
166\section{Notation}
167The syntax notation used in this document is the same as in the \Celeven standard, with one exception: ellipsis in the definition of a nonterminal, as in ``\emph{declaration:} \ldots'', indicates that these rules extend a previous definition, which occurs in this document or in the \Celeven standard.
168
169
170\section{Concepts}
171
172
173\subsection{Scopes of identifiers}\index{scopes}
174
175\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 \Index{name space}, instead of hiding them.
176The 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 ©type©\use{type} or ©typedef©\use{typedef} declaration and the other is not.
177The outer declaration becomes \Index{visible} when the scope of the inner declaration terminates.
178\begin{rationale}
179Hence, a \CFA program can declare an ©int v© and a ©float v© in the same scope;
180a \CC program can not.
181\end{rationale}
182
183
184\subsection{Linkage of identifiers}
185\index{linkage}
186
187\CFA's linkage rules differ from C's in only one respect: instances of a particular identifier with external or internal linkage do not necessarily denote the same object or function.
188Instead, in the set of translation units and libraries that constitutes an entire program, any two instances of a particular identifier with \Index{external linkage} denote the same object or function if they have \Index{compatible type}s, 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.
189Within one translation unit, each instance of an identifier with \Index{internal linkage} denotes the same object or function in the same circumstances.
190Identifiers with \Index{no linkage} always denote unique entities.
191\begin{rationale}
192A \CFA program can declare an ©extern int v© and an ©extern float v©;
193a C program cannot.
194\end{rationale}
195
196
197\setcounter{subsection}{8}
198\subsection{Generic Types}
199
200
201\subsubsection{Semantics}
202
203\CFA provides a capability for generic types;
204using this capability a single "generic type generator" can be written that can represent multiple concrete type instantiations by substitution of the "type parameters" of the generic type for concrete types.
205Syntactically a generic type generator is represented by putting a forall specifier on a struct or union declaration, as defined in \VRef{forall}.
206An instantiation of the generic type is written by specifying the type parameters in parentheses after the name of the generic type generator:
207\begin{lstlisting}
208forall( otype T | sumable( T ) ) struct pair {
209        T x;
210        T y;
211};
212pair( int ) p = { 3, 14 };
213\end{lstlisting}
214
215The type parameters in an instantiation of a generic type must satisfy any constraints in the forall specifier on the type generator declaration, e.g., ©sumable©.
216The instantiation then has the semantics that would result if the type parameters were substituted into the type generator declaration by macro substitution.
217
218Polymorphic functions may have generic types as parameters, and those generic types may use type parameters of the polymorphic function as type parameters of the generic type:
219\begin{lstlisting}
220forall( otype T ) void swap( pair(T) *p ) {
221        T z = p->x;
222        p->x = p->y;
223        p->y = z;
224}
225\end{lstlisting}
226
227
228\subsubsection{Constraints}
229
230To avoid unduly constraining implementors, the generic type generator definition must be visible at any point where it is instantiated.
231Forward declarations of generic type generators are not forbidden, but the definition must be visible to instantiate the generic type.  Equivalently, instantiations of generic types are not allowed to be incomplete types.
232
233\examples
234\begin{lstlisting}
235forall( otype T ) struct A;
236
237forall( otype T ) struct B {
238        A(T) *a;                        // legal, but cannot instantiate B(T)
239};
240
241B(T) x;                                 // illegal, *x.a is of an incomplete generic type
242 
243forall( otype T ) struct A {
244        B( T ) *b;
245};
246
247B( T ) y;                               // legal, *x.a is now of a complete generic type
248
249// box.h:
250        forall( otype T ) struct box;
251        forall( otype T ) box( T ) *make_box( T );
252        forall( otype T ) void use_box( box( T ) *b );
253       
254// main.c:
255        box( int ) *b = make_box( 42 ); // illegal, definition of box not visible
256        use_box( b );           // illegal
257\end{lstlisting}
258
259
260\section{Conversions}
261\CFA defines situations where values of one type are automatically converted to another type.
262These conversions are called \define{implicit conversion}s.
263The programmer can request \define{explicit conversion}s using cast expressions.
264
265
266\subsection{Arithmetic operands}
267
268
269\setcounter{subsubsection}{8}
270\subsubsection{Safe arithmetic conversions}
271
272In C, a pattern of conversions known as the \define{usual arithmetic conversion}s is used with most binary arithmetic operators to convert the operands to a common type and determine the type of the operator's result.
273In \CFA, these conversions play a role in overload resolution, and collectively are called the \define{safe arithmetic conversion}s.
274
275Let ©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$.
276Let ©unsigned$_{mr}$© be the unsigned integer type with maximal rank.
277
278The following conversions are \emph{direct} safe arithmetic conversions.
279\begin{itemize}
280\item
281The \Index{integer promotion}s.
282\item
283For every rank $r$ greater than or equal to the rank of ©int©, conversion from ©int$_r$© to ©unsigned$_r$©.
284\item
285For every rank $r$ greater than or equal to the rank of ©int©, where ©int$_{r+1}$© exists and can represent all values of ©unsigned$_r$©, conversion from ©unsigned$_r$© to ©int$_{r+1}$©.
286\item
287Conversion from ©unsigned$_{mr}$© to ©float©.
288\item
289Conversion from an enumerated type to its compatible integer type.
290\item
291Conversion from ©float© to ©double©, and from ©double© to ©long double©.
292\item
293Conversion from ©float _Complex© to ©double _Complex©, and from ©double _Complex© to ©long double _Complex©.
294\begin{sloppypar}
295\item
296Conversion from ©float _Imaginary© to ©double _Imaginary©, and from ©double _Imaginary© to ©long double _Imaginary©, if the implementation supports imaginary types.
297\end{sloppypar}
298\end{itemize}
299
300If type ©T© can be converted to type ©U© by a safe direct arithmetic conversion and type ©U© can be converted to type ©V© by a safe arithmetic conversion, then the conversion from ©T© to type ©V© is an \emph{indirect} safe arithmetic conversion.
301
302\begin{rationale}
303Note that \Celeven does not include conversion from \Index{real type}s to \Index{complex type}s in the usual arithmetic conversions, and \CFA does not include them as safe conversions.
304\end{rationale}
305
306
307\subsection{Other operands}
308
309
310\setcounter{subsubsection}{3}
311\subsubsection{Anonymous structures and unions}
312\label{anon-conv}
313
314If an expression's type is a pointer to a structure or union type that has a member that is an \Index{anonymous structure} or an \Index{anonymous union}, it can be implicitly converted\index{implicit conversion} to a pointer to the anonymous structure's or anonymous union's type.
315The result of the conversion is a pointer to the member.
316
317\examples
318\begin{lstlisting}
319struct point {
320        int x, y;
321};
322void move_by( struct point * p1, struct point * p2 ) {§\impl{move_by}§
323        p1->x += p2.x;
324        p1->y += p2.y;
325}
326struct color_point {
327        enum { RED, BLUE, GREEN } color;
328        struct point;
329} cp1, cp2;
330move_to( &cp1, &cp2 );
331\end{lstlisting}
332Thanks to implicit conversion, the two arguments that ©move_by()© receives are pointers to ©cp1©'s second member and ©cp2©'s second member.
333
334
335\subsubsection{Specialization}
336A function or value whose type is polymorphic may be implicitly converted to one whose type is \Index{less polymorphic} by binding values to one or more of its \Index{inferred parameter}.
337Any value that is legal for the inferred parameter may be used, including other inferred parameters.
338
339If, after the inferred parameter binding, an \Index{assertion parameter} has no inferred parameters in its type, then an object or function must be visible at the point of the specialization that has the same identifier as the assertion parameter and has a type that is compatible\index{compatible type} with or can be specialized to the type of the assertion parameter.
340The assertion parameter is bound to that object or function.
341
342The type of the specialization is the type of the original with the bound inferred parameters and the bound assertion parameters replaced by their bound values.
343
344\examples
345The type
346\begin{lstlisting}
347forall( otype T, otype U ) void (*)( T, U );
348\end{lstlisting}
349can be specialized to (among other things)
350\begin{lstlisting}
351forall( otype T ) void (*)( T, T );             // U bound to T
352forall( otype T ) void (*)( T, real );  // U bound to real
353forall( otype U ) void (*)( real, U );  // T bound to real
354void f( real, real );                                   // both bound to real
355\end{lstlisting}
356
357The type
358\begin{lstlisting}
359forall( otype T | T ?+?( T, T ) ) T (*)( T );
360\end{lstlisting}
361can be specialized to (among other things)
362\begin{lstlisting}
363int (*)( int );         // T bound to int, and T ?+?(T, T ) bound to int ?+?( int, int )
364\end{lstlisting}
365
366
367\subsubsection{Safe conversions}
368
369A \define{direct safe conversion} is one of the following conversions:
370\begin{itemize}
371\item
372a direct safe arithmetic conversion;
373\item
374from any object type or incomplete type to ©void©;
375\item
376from a pointer to any non-©void© type to a pointer to ©void©;
377\item
378from a pointer to any type to a pointer to a more qualified version of the type\index{qualified type};
379\item
380from a pointer to a structure or union type to a pointer to the type of a member of the structure or union that is an \Index{anonymous structure} or an \Index{anonymous union};
381\item
382within the scope of an initialized \Index{type declaration}, conversions between a type and its implementation or between a pointer to a type and a pointer to its implementation.
383\end{itemize}
384
385Conversions that are not safe conversions are \define{unsafe conversion}s.
386\begin{rationale}
387As in C, there is an implicit conversion from ©void *© to any pointer type.
388This is clearly dangerous, and \CC does not have this implicit conversion.
389\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.
390\end{rationale}
391
392
393\subsection{Conversion cost}
394
395The \define{conversion cost} of a safe\index{safe conversion} conversion\footnote{Unsafe\index{unsafe conversion} conversions do not have defined conversion costs.} is a measure of how desirable or undesirable it is.
396It is defined as follows.
397\begin{itemize}
398\item
399The cost of a conversion from any type to itself is 0.
400
401\item
402The cost of a direct safe conversion is 1.
403
404\item
405The cost of an indirect safe arithmetic conversion is the smallest number of direct conversions needed to make up the conversion.
406\end{itemize}
407
408\examples
409In the following, assume an implementation that does not provide any extended integer types.
410
411\begin{itemize}
412\item
413The cost of an implicit conversion from ©int© to ©long© is 1.
414The cost of an implicit conversion from ©long© to ©double© is 3, because it is defined in terms of conversions from ©long© to ©unsigned long©, then to ©float©, and then to ©double©.
415
416\item
417If ©int© can represent all the values of ©unsigned short©, then the cost of an implicit conversion from ©unsigned short© to ©unsigned© is 2: ©unsigned short© to ©int© to ©unsigned©.
418Otherwise, ©unsigned short© is converted directly to ©unsigned©, and the cost is 1.
419
420\item
421If ©long© can represent all the values of ©unsigned©, then the conversion cost of ©unsigned© to ©long© is 1.
422Otherwise, the conversion is an unsafe conversion, and its conversion cost is undefined.
423\end{itemize}
424
425
426\section{Lexical elements}
427
428
429\subsection{Keywords}
430
431\begin{syntax}
432\lhs{keyword} one of
433\rhs \dots
434\rhs \input{keywords}
435\end{syntax}
436
437
438\subsection{Identifiers}
439
440\CFA allows operator \Index{overloading} by associating operators with special function identifiers.
441Furthermore, the constants ``©0©'' and ``©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.
442Programmers can use these identifiers to declare functions and objects that implement operators and constants for their own types.
443
444
445\setcounter{subsubsection}{2}
446\subsubsection{Constant identifiers}
447
448\begin{syntax}
449\oldlhs{identifier}
450\rhs ©0©
451\rhs ©1©
452\end{syntax}
453
454\index{constant identifiers}\index{identifiers!for constants} The tokens ``©0©''\impl{0} and ``©1©''\impl{1} are identifiers.
455No other tokens defined by the rules for integer constants are considered to be identifiers.
456\begin{rationale}
457Why ``©0©'' and ``©1©''? Those integers have special status in C.
458All scalar types can be incremented and decremented, which is defined in terms of adding or subtracting 1.
459The operations ``©&&©'', ``©||©'', and ``©!©'' can be applied to any scalar arguments, and are defined in terms of comparison against 0.
460A \nonterm{constant-expression} that evaluates to 0 is effectively compatible with every pointer type.
461
462In 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.
463However, 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.
464Defining special constants for a user-defined type is more efficient than defining a conversion to the type from ©_Bool©.
465
466Why \emph{just} ``©0©'' and ``©1©''? Why not other integers? No other integers have special status in C.
467A facility that let programmers declare specific constants---``©const Rational 12©'', for instance---would not be much of an improvement.
468Some facility for defining the creation of values of programmer-defined types from arbitrary integer tokens would be needed.
469The complexity of such a feature doesn't seem worth the gain.
470\end{rationale}
471
472
473\subsubsection{Operator identifiers}
474
475\index{operator identifiers}\index{identifiers!for operators} Table \ref{opids} lists the programmer-definable operator identifiers and the operations they are associated with.
476Functions that are declared with (or pointed at by function pointers that are declared with) these identifiers can be called by expressions that use the operator tokens and syntax, or the operator identifiers and ``function call'' syntax.
477The relationships between operators and function calls are discussed in descriptions of the operators.
478
479\begin{table}[hbt]
480\hfil
481\begin{tabular}[t]{ll}
482%identifier & operation \\ \hline
483©?[?]© & subscripting \impl{?[?]}\\
484©?()© & function call \impl{?()}\\
485©?++© & postfix increment \impl{?++}\\
486©?--© & postfix decrement \impl{?--}\\
487©++?© & prefix increment \impl{++?}\\
488©--?© & prefix decrement \impl{--?}\\
489©*?© & dereference \impl{*?}\\
490©+?© & unary plus \impl{+?}\\
491©-?© & arithmetic negation \impl{-?}\\
492©~?© & bitwise negation \impl{~?}\\
493©!?© & logical complement \impl{"!?}\\
494©?*?© & multiplication \impl{?*?}\\
495©?/?© & division \impl{?/?}\\
496\end{tabular}\hfil
497\begin{tabular}[t]{ll}
498%identifier & operation \\ \hline
499©?%?© & remainder \impl{?%?}\\
500©?+?© & addition \impl{?+?}\\
501©?-?© & subtraction \impl{?-?}\\
502©?<<?© & left shift \impl{?<<?}\\
503©?>>?© & right shift \impl{?>>?}\\
504©?<?© & less than \impl{?<?}\\
505©?<=?© & less than or equal \impl{?<=?}\\
506©?>=?© & greater than or equal \impl{?>=?}\\
507©?>?© & greater than \impl{?>?}\\
508©?==?© & equality \impl{?==?}\\
509©?!=?© & inequality \impl{?"!=?}\\
510©?&& bitwise AND \impl{?&?}\\
511\end{tabular}\hfil
512\begin{tabular}[t]{ll}
513%identifier & operation \\ \hline
514©?^& exclusive OR \impl{?^?}\\
515©?|?© & inclusive OR \impl{?"|?}\\
516©?=?© & simple assignment \impl{?=?}\\
517©?*=?© & multiplication assignment \impl{?*=?}\\
518©?/=?© & division assignment \impl{?/=?}\\
519©?%=?© & remainder assignment \impl{?%=?}\\
520©?+=?© & addition assignment \impl{?+=?}\\
521©?-=?© & subtraction assignment \impl{?-=?}\\
522©?<<=?© & left-shift assignment \impl{?<<=?}\\
523©?>>=?© & right-shift assignment \impl{?>>=?}\\
524©?&=?© & bitwise AND assignment \impl{?&=?}\\
525©?^=?© & exclusive OR assignment \impl{?^=?}\\
526©?|=?© & inclusive OR assignment \impl{?"|=?}\\
527\end{tabular}
528\hfil
529\caption{Operator Identifiers}
530\label{opids}
531\end{table}
532
533\begin{rationale}
534Operator identifiers are made up of the characters of the operator token, with question marks added to mark the positions of the arguments of operators.
535The question marks serve as mnemonic devices;
536programmers can not create new operators by arbitrarily mixing question marks and other non-alphabetic characters.
537Note that prefix and postfix versions of the increment and decrement operators are distinguished by the position of the question mark.
538\end{rationale}
539
540\begin{rationale}
541The use of ``©?©'' in identifiers means that some C programs are not \CFA programs.  For instance, the sequence of characters ``©(i < 0)?--i:i©'' is legal in a C program, but a
542\CFA compiler detects a syntax error because it treats ``©?--©'' as an identifier, not as the two tokens ``©?©'' and ``©--©''.
543\end{rationale}
544
545\begin{rationale}
546Certain operators \emph{cannot} be defined by the programmer:
547\begin{itemize}
548\item
549The logical operators ``©&&©'' and ``©||©'', and the conditional operator ``©?:©''.
550These 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.
551Note that the definitions of ``©&&©'' and ``©||©'' say that they work by checking that their arguments are unequal to 0, so defining ``©!=©'' and ``©0©'' for user-defined types is enough to allow them to be used in logical expressions.
552
553\item
554The comma operator\index{comma expression}.
555It is a control-flow operator like those above.
556Changing its meaning seems pointless and confusing.
557
558\item
559The ``address of'' operator.
560It would seem useful to define a unary ``©&©'' operator that returns values of some programmer-defined pointer-like type.
561The problem lies with the type of the operator.
562Consider the expression ``©p = &x©'', where ©x© is of type ©T© and ©p© has the programmer-defined type ©T_ptr©.
563The expression might be treated as a call to the unary function ``©&?©''.
564Now what is the type of the function's parameter? It can not be ©T©, because then ©x© would be passed by value, and there is no way to create a useful pointer-like result from a value.
565Hence the parameter must have type ©T *©.
566But then the expression must be rewritten as ``©p = &?( &x )©''
567---which doesn't seem like progress!
568
569The 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''.
570It seems simpler to define a conversion function from ©T *© to ©T_ptr©.
571
572\item
573The ©sizeof© operator.
574It is already defined for every object type, and intimately tied into the language's storage allocation model.
575Redefining it seems pointless.
576
577\item
578The ``member of'' operators ``©.©'' and ``©->©''.
579These are not really infix operators, since their right ``operand'' is not a value or object.
580
581\item
582Cast operators\index{cast expression}.
583Anything that can be done with an explicit cast can be done with a function call.
584The difference in syntax is small.
585\end{itemize}
586\end{rationale}
587
588
589\section{Expressions}
590
591\CFA allows operators and identifiers to be overloaded.
592Hence, each expression can have a number of \define{interpretation}s, each of which has a different type.
593The interpretations that are potentially executable are called \define{valid interpretation}s.
594The set of interpretations depends on the kind of expression and on the interpretations of the subexpressions that it contains.
595The rules for determining the valid interpretations of an expression are discussed below for each kind of expression.
596Eventually the context of the outermost expression chooses one interpretation of that expression.
597
598An \define{ambiguous interpretation} is an interpretation which does not specify the exact object or function denoted by every identifier in the expression.
599An expression can have some interpretations that are ambiguous and others that are unambiguous.
600An expression that is chosen to be executed shall not be ambiguous.
601
602The \define{best valid interpretations} are the valid interpretations that use the fewest unsafe\index{unsafe conversion} conversions.
603Of these, the best are those where the functions and objects involved are the least polymorphic\index{less polymorphic}.
604Of these, the best have the lowest total \Index{conversion cost}, including all implicit conversions in the argument expressions.
605Of these, the best have the highest total conversion cost for the implicit conversions
606(if any) applied to the argument expressions.
607If there is no single best valid interpretation, or if the best valid interpretation is ambiguous, then the resulting interpretation is ambiguous\index{ambiguous interpretation}.
608
609\begin{rationale}
610\CFA's rules for selecting the best interpretation are designed to allow overload resolution to mimic C's operator semantics.
611In C, the ``usual arithmetic conversions'' are applied to the operands of binary operators if necessary to convert the operands to types with a common real type.
612In \CFA, those conversions are ``safe''.
613The ``fewest unsafe conversions'' rule ensures that the usual conversions are done, if possible.
614The ``lowest total expression cost'' rule chooses the proper common type.
615The 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: ©(double)-i© will be preferred to ©-(double)i©.
616
617The ``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.
618It also gives preference to monomorphic values (such as the ©int© ©0©) over polymorphic values (such as the \Index{null pointer} ©0©\use{0}).
619However, interpretations that call polymorphic functions are preferred to interpretations that perform unsafe conversions, because those conversions potentially lose accuracy or violate strong typing.
620
621There are two notable differences between \CFA's overload resolution rules and the rules for
622\CC defined in \cite{C++}.
623First, the result type of a function plays a role.
624In \CC, a function call must be completely resolved based on the arguments to the call in most circumstances.
625In \CFA, a function call may have several interpretations, each with a different result type, and the interpretations of the containing context choose among them.
626Second, safe conversions are used to choose among interpretations of all sorts of functions;
627in \CC, the ``usual arithmetic conversions'' are a separate set of rules that apply only to the built-in operators.
628\end{rationale}
629
630Expressions involving certain operators\index{operator identifiers} are considered to be equivalent to function calls.
631A transformation from ``operator'' syntax to ``function call'' syntax is defined by \define{rewrite rules}.
632Each operator has a set of predefined functions that overload its identifier.
633Overload resolution determines which member of the set is executed in a given expression.
634The functions have \Index{internal linkage} and are implicitly declared with \Index{file scope}.
635The predefined functions and rewrite rules are discussed below for each of these operators.
636\begin{rationale}
637Predefined functions and constants have internal linkage because that simplifies optimization in traditional compile-and-link environments.
638For instance, ``©an_int + an_int©'' is equivalent to ``©?+?(an_int, an_int)©''.
639If integer addition has not been redefined in the current scope, a compiler can generate code to perform the addition directly.
640If predefined functions had external linkage, this optimization would be difficult.
641\end{rationale}
642
643\begin{rationale}
644Since each subsection describes the interpretations of an expression in terms of the interpretations of its subexpressions, this chapter can be taken as describing an overload resolution algorithm that uses one bottom-up pass over an expression tree.
645Such an algorithm was first described (for Ada) by Baker~\cite{Bak:overload}.
646It is extended here to handle polymorphic functions and arithmetic conversions.
647The overload resolution rules and the predefined functions have been chosen so that, in programs that do not introduce overloaded declarations, expressions will have the same meaning in C and in \CFA.
648\end{rationale}
649
650\begin{rationale}
651Expression syntax is quoted from the \Celeven standard.
652The syntax itself defines the precedence and associativity of operators.
653The sections are arranged in decreasing order of precedence, with all operators in a section having the same precedence.
654\end{rationale}
655
656
657\subsection{Primary expressions}
658
659\begin{syntax}
660\lhs{primary-expression}
661\rhs \nonterm{identifier}
662\rhs \nonterm{constant}
663\rhs \nonterm{string-literal}
664\rhs ©(© \nonterm{expression} ©)©
665\rhs \nonterm{generic-selection}
666\end{syntax}
667
668\predefined
669\begin{lstlisting}
670const int 1;§\use{1}§
671const int 0;§\use{0}§
672forall( dtype DT ) DT * const 0;
673forall( ftype FT ) FT * const 0;
674\end{lstlisting}
675
676\semantics
677The \Index{valid interpretation} of an \nonterm{identifier} are given by the visible\index{visible} declarations of the identifier.
678
679A \nonterm{constant} or \nonterm{string-literal} has one valid interpretation, which has the type and value defined by \Celeven.
680The predefined integer identifiers ``©1©'' and ``©0©'' have the integer values 1 and 0, respectively.
681The other two predefined ``©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.
682
683A parenthesised expression has the same interpretations as the contained \nonterm{expression}.
684
685\examples
686The expression ©(void *)0©\use{0} specializes the (polymorphic) null pointer to a null pointer to ©void©. ©(const void *)0© does the same, and also uses a safe conversion from ©void *© to ©const void *©.
687In each case, the null pointer conversion is better\index{best valid interpretations} than the unsafe conversion of the integer ©0© to a pointer.
688
689\begin{rationale}
690Note that the predefined identifiers have addresses.
691
692\CFA does not have C's concept of ``null pointer constants'', which are not typed values but special strings of tokens.
693The C token ``©0©'' is an expression of type ©int© with the value ``zero'', and it \emph{also} is a null pointer constant.
694Similarly, ``©(void *)0© is an expression of type ©(void *)© whose value is a null pointer, and it also is a null pointer constant.
695However, in C, ``©(void *)(void *)0©'' is
696\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.
697
698\CFA handles these cases through overload resolution.
699The declaration
700\begin{lstlisting}
701forall( dtype DT ) DT * const 0;
702\end{lstlisting} means that ©0© is a polymorphic object, and contains a value that can have \emph{any} pointer-to-object type or pointer-to-incomplete type.
703The only such value is the null pointer.
704Therefore the type \emph{alone} is enough to identify a null pointer.
705Where C defines an operator with a special case for the null pointer constant, \CFA defines predefined functions with a polymorphic object parameter.
706\end{rationale}
707
708
709\subsubsection{Generic selection}
710
711\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.
712If a generic selection has no ©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.
713
714\semantics
715A generic selection has the same interpretations as its result expression.
716
717
718\subsection{Postfix operators}
719
720\begin{syntax}
721\lhs{postfix-expression}
722\rhs \nonterm{primary-expression}
723\rhs \nonterm{postfix-expression} ©[© \nonterm{expression} ©]©
724\rhs \nonterm{postfix-expression} ©(©
725         \nonterm{argument-expression-list}\opt ©)©
726\rhs \nonterm{postfix-expression} ©.© \nonterm{identifier}
727\rhs \nonterm{postfix-expression} ©->© \nonterm{identifier}
728\rhs \nonterm{postfix-expression} ©++©
729\rhs \nonterm{postfix-expression} ©--©
730\rhs ©(© \nonterm{type-name} ©)© ©{© \nonterm{initializer-list} ©}©
731\rhs ©(© \nonterm{type-name} ©)© ©{© \nonterm{initializer-list} ©,© ©}©
732\lhs{argument-expression-list}
733\rhs \nonterm{assignment-expression}
734\rhs \nonterm{argument-expression-list} ©,©
735         \nonterm{assignment-expression}
736\end{syntax}
737
738\rewriterules
739\begin{lstlisting}
740a[b] => ?[?]( b, a ) // if a has integer type§\use{?[?]}§
741a[b] => ?[?]( a, b ) // otherwise
742a( §\emph{arguments}§ ) => ?()( a, §\emph{arguments}§ )§\use{?()}§
743a++ => ?++(&( a ))§\use{?++}§
744a-- => ?--(&( a ))§\use{?--}§
745\end{lstlisting}
746
747
748\subsubsection{Array subscripting}
749
750\predefined
751\begin{lstlisting}
752forall( otype T ) lvalue T ?[?]( T *, ptrdiff_t );§\use{ptrdiff_t}§
753forall( otype T ) lvalue _Atomic T ?[?]( _Atomic T *, ptrdiff_t );
754forall( otype T ) lvalue const T ?[?]( const T *, ptrdiff_t );
755forall( otype T ) lvalue restrict T ?[?]( restrict T *, ptrdiff_t );
756forall( otype T ) lvalue volatile T ?[?]( volatile T *, ptrdiff_t );
757forall( otype T ) lvalue _Atomic const T ?[?]( _Atomic const T *, ptrdiff_t );
758forall( otype T ) lvalue _Atomic restrict T ?[?]( _Atomic restrict T *, ptrdiff_t );
759forall( otype T ) lvalue _Atomic volatile T ?[?]( _Atomic volatile T *, ptrdiff_t );
760forall( otype T ) lvalue const restrict T ?[?]( const restrict T *, ptrdiff_t );
761forall( otype T ) lvalue const volatile T ?[?]( const volatile T *, ptrdiff_t );
762forall( otype T ) lvalue restrict volatile T ?[?]( restrict volatile T *, ptrdiff_t );
763forall( otype T ) lvalue _Atomic const restrict T ?[?]( _Atomic const restrict T *, ptrdiff_t );
764forall( otype T ) lvalue _Atomic const volatile T ?[?]( _Atomic const volatile T *, ptrdiff_t );
765forall( otype T ) lvalue _Atomic restrict volatile T ?[?]( _Atomic restrict volatile T *, ptrdiff_t );
766forall( otype T ) lvalue const restrict volatile T ?[?]( const restrict volatile T *, ptrdiff_t );
767forall( otype T ) lvalue _Atomic const restrict volatile T ?[?]( _Atomic const restrict volatile T *, ptrdiff_t );
768\end{lstlisting}
769\semantics
770The interpretations of subscript expressions are the interpretations of the corresponding function call expressions.
771\begin{rationale}
772C defines subscripting as pointer arithmetic in a way that makes ©a[i]© and ©i[a]© equivalent. \CFA provides the equivalence through a rewrite rule to reduce the number of overloadings of ©?[?]©.
773
774Subscript expressions are rewritten as function calls that pass the first parameter by value.
775This is somewhat unfortunate, since array-like types tend to be large.
776The alternative is to use the rewrite rule ``©a[b] => ?[?](&(a), b)©''.
777However, C semantics forbid this approach: the ©a© in ``©a[b]©'' can be an arbitrary pointer value, which does not have an address.
778
779The repetitive form of the predefined identifiers shows up a deficiency\index{deficiencies!pointers
780 to qualified types} of \CFA's type system.
781Type qualifiers are not included in type values, so polymorphic functions that take pointers to arbitrary types often come in one flavor for each possible qualification of the pointed-at type.
782\end{rationale}
783
784
785\subsubsection{Function calls}
786
787\semantics
788A \define{function designator} is an interpretation of an expression that has function type.
789The
790\nonterm{postfix-expression} in a function call may have some interpretations that are function designators and some that are not.
791
792For those interpretations of the \nonterm{postfix-expression} that are not function designators, the expression is rewritten and becomes a call of a function named ``©?()©''.
793The valid interpretations of the rewritten expression are determined in the manner described below.
794
795Each combination of function designators and argument interpretations is considered.
796For those interpretations of the \nonterm{postfix-expression} that are \Index{monomorphic function} designators, the combination has a \Index{valid interpretation} if the function designator accepts the number of arguments given, and each argument interpretation matches the corresponding explicit parameter:
797\begin{itemize}
798\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
799\item if the function designator's type does not include a prototype or if the argument corresponds to ``©...©'' in a prototype, a \Index{default argument promotion} is applied to it.
800\end{itemize}
801The type of the valid interpretation is the return type of the function designator.
802
803For those combinations where the interpretation of the \nonterm{postfix-expression} is a \Index{polymorphic function} designator and the function designator accepts the number of arguments given, there shall be at least one set of \define{implicit argument}s for the implicit parameters such that
804\begin{itemize}
805\item
806If the declaration of the implicit parameter uses \Index{type-class} ©type©\use{type}, the implicit argument must be an object type;
807if it uses ©dtype©, the implicit argument must be an object type or an incomplete type;
808and if it uses ©ftype©, the implicit argument must be a function type.
809
810\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.
811
812\item the remaining explicit arguments must match the remaining explicit parameters, as described for monomorphic function designators.
813
814\item for each \Index{assertion parameter} in the function designator's type, there must be an object or function with the same identifier that is visible at the call site and whose type is compatible with or can be specialized to the type of the assertion declaration.
815\end{itemize}
816There is a valid interpretation for each such set of implicit parameters.
817The type of each valid interpretation is the return type of the function designator with implicit parameter values substituted for the implicit arguments.
818
819A valid interpretation is ambiguous\index{ambiguous interpretation} if the function designator or any of the argument interpretations is ambiguous.
820
821Every valid interpretation whose return type is not compatible with any other valid interpretation's return type is an interpretation of the function call expression.
822
823Every set of valid interpretations that have mutually compatible\index{compatible type} result types also produces an interpretation of the function call expression.
824The type of the interpretation is the \Index{composite type} of the types of the valid interpretations, and the value of the interpretation is that of the \Index{best valid interpretation}.
825\begin{rationale}
826One 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}.
827For instance, it should be possible to replace a function ``©int f( int );©'' with ``©forall( otype T ) T f( T );©'' without affecting any calls of ©f©.
828
829\CFA\index{deficiencies!generalizability} does not fully possess this property, because \Index{unsafe conversion} are not done when arguments are passed to polymorphic parameters.
830Consider
831\begin{lstlisting}
832float g( float, float );
833int i;
834float f;
835double d;
836f = g( f, f );          // (1)
837f = g( i, f );          // (2) (safe conversion to float)
838f = g( d, f );          // (3) (unsafe conversion to float)
839\end{lstlisting}
840If ©g© was replaced by ``©forall( otype T ) T g( T, T );©'', the first and second calls would be unaffected, but the third would change: ©f© would be converted to ©double©, and the result would be a ©double©.
841
842Another example is the function ``©void h( int *);©''.
843This function can be passed a ©void *© argument, but the generalization ``©forall( otype T ) void h( T *);©'' can not.
844In this case, ©void© is not a valid value for ©T© because it is not an object type.
845If unsafe conversions were allowed, ©T© could be inferred to be \emph{any} object type, which is undesirable.
846\end{rationale}
847
848\examples
849A function called ``©?()©'' might be part of a numerical differentiation package.
850\begin{lstlisting}
851extern otype Derivative;
852extern double ?()( Derivative, double );
853extern Derivative derivative_of( double (*f)( double ) );
854extern double sin( double );
855
856Derivative sin_dx = derivative_of( sin );
857double d;
858d = sin_dx( 12.9 );
859\end{lstlisting}
860Here, the only interpretation of ©sin_dx© is as an object of type ©Derivative©.
861For that interpretation, the function call is treated as ``©?()( sin_dx, 12.9 )©''.
862\begin{lstlisting}
863int f( long );          // (1)
864int f( int, int );      // (2)
865int f( int *);          // (3)
866int i = f( 5 );         // calls (1)
867\end{lstlisting}
868Function (1) provides a valid interpretation of ``©f( 5 )©'', using an implicit ©int© to ©long© conversion.
869The other functions do not, since the second requires two arguments, and since there is no implicit conversion from ©int© to ©int *© that could be used with the third function.
870
871\begin{lstlisting}
872forall( otype T ) T h( T );
873double d = h( 1.5 );
874\end{lstlisting}
875``©1.5©'' is a ©double© constant, so ©T© is inferred to be ©double©, and the result of the function call is a ©double©.
876
877\begin{lstlisting}
878forall( otype T, otype U ) void g( T, U );      // (4)
879forall( otype T ) void g( T, T );                       // (5)
880forall( otype T ) void g( T, long );            // (6)
881void g( long, long );                                           // (7)
882double d;
883int i;
884int *p;
885g( d, d );                                                                      // calls (5)
886g( d, i );                                                                      // calls (6)
887g( i, i );                                                                      // calls (7)
888g( i, p );                                                                      // calls (4)
889\end{lstlisting}
890The first call has valid interpretations for all four versions of ©g©. (6) and (7) are discarded because they involve unsafe ©double©-to-©long© conversions. (5) is chosen because it is less polymorphic than (4).
891
892For the second call, (7) is again discarded.
893Of the remaining interpretations for (4), (5), and (6) (with ©i© converted to ©long©), (6) is chosen because it is the least polymorphic.
894
895The third call has valid interpretations for all of the functions;
896(7) is chosen since it is not polymorphic at all.
897
898The fourth call has no interpretation for (5), because its arguments must have compatible type. (4) is chosen because it does not involve unsafe conversions.
899\begin{lstlisting}
900forall( otype T ) T min( T, T );
901double max( double, double );
902trait min_max( T ) {§\impl{min_max}§
903        T min( T, T );
904        T max( T, T );
905}
906forall( otype U | min_max( U ) ) void shuffle( U, U );
907shuffle( 9, 10 );
908\end{lstlisting}
909The only possibility for ©U© is ©double©, because that is the type used in the only visible ©max© function. 9 and 10 must be converted to ©double©, and ©min© must be specialized with ©T© bound to ©double©.
910\begin{lstlisting}
911extern void q( int );                                           // (8)
912extern void q( void * );                                        // (9)
913extern void r();
914q( 0 );
915r( 0 );
916\end{lstlisting}
917The ©int 0© could be passed to (8), or the ©(void *)© \Index{specialization} of the null pointer\index{null pointer} ©0©\use{0} could be passed to (9).
918The former is chosen because the ©int© ©0© is \Index{less polymorphic}.
919For the same reason, ©int© ©0© is passed to ©r()©, even though it has \emph{no} declared parameter types.
920
921
922\subsubsection{Structure and union members}
923
924\semantics In the member selection expression ``©s©.©m©'', there shall be at least one interpretation of ©s© whose type is a structure type or union type containing a member named ©m©.
925If two or more interpretations of ©s© have members named ©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.
926If an interpretation of ©s© has a member ©m© whose type is not compatible with any other ©s©'s ©m©, then the expression has an interpretation with the member's type.
927The expression has no other interpretations.
928
929The expression ``©p->m©'' has the same interpretations as the expression ``©(*p).m©''.
930
931
932\subsubsection{Postfix increment and decrement operators}
933
934\predefined
935\begin{lstlisting}
936_Bool ?++( volatile _Bool * ), ?++( _Atomic volatile _Bool * );
937char ?++( volatile char * ), ?++( _Atomic volatile char * );
938signed char ?++( volatile signed char * ), ?++( _Atomic volatile signed char * );
939unsigned char ?++( volatile signed char * ), ?++( _Atomic volatile signed char * );
940short int ?++( volatile short int * ), ?++( _Atomic volatile short int * );
941unsigned short int ?++( volatile unsigned short int * ), ?++( _Atomic volatile unsigned short int * );
942int ?++( volatile int * ), ?++( _Atomic volatile int * );
943unsigned int ?++( volatile unsigned int * ), ?++( _Atomic volatile unsigned int * );
944long int ?++( volatile long int * ), ?++( _Atomic volatile long int * );
945long unsigned int ?++( volatile long unsigned int * ), ?++( _Atomic volatile long unsigned int * );
946long long int ?++( volatile long long int * ), ?++( _Atomic volatile long long int * );
947long long unsigned ?++( volatile long long unsigned int * ), ?++( _Atomic volatile long long unsigned int * );
948float ?++( volatile float * ), ?++( _Atomic volatile float * );
949double ?++( volatile double * ), ?++( _Atomic volatile double * );
950long double ?++( volatile long double * ), ?++( _Atomic volatile long double * );
951
952forall( otype T ) T * ?++( T * restrict volatile * ), * ?++( T * _Atomic restrict volatile * );
953forall( otype T ) _Atomic T * ?++( _Atomic T * restrict volatile * ), * ?++( _Atomic T * _Atomic restrict volatile * );
954forall( otype T ) const T * ?++( const T * restrict volatile * ), * ?++( const T * _Atomic restrict volatile * );
955forall( otype T ) volatile T * ?++( volatile T * restrict volatile * ), * ?++( volatile T * _Atomic restrict volatile * );
956forall( otype T ) restrict T * ?++( restrict T * restrict volatile * ), * ?++( restrict T * _Atomic restrict volatile * );
957forall( otype T ) _Atomic const T * ?++( _Atomic const T * restrict volatile * ),
958        * ?++( _Atomic const T * _Atomic restrict volatile * );
959forall( otype T ) _Atomic restrict T * ?++( _Atomic restrict T * restrict volatile * ),
960        * ?++( _Atomic restrict T * _Atomic restrict volatile * );
961forall( otype T ) _Atomic volatile T * ?++( _Atomic volatile T * restrict volatile * ),
962        * ?++( _Atomic volatile T * _Atomic restrict volatile * );
963forall( otype T ) const restrict T * ?++( const restrict T * restrict volatile * ),
964        * ?++( const restrict T * _Atomic restrict volatile * );
965forall( otype T ) const volatile T * ?++( const volatile T * restrict volatile * ),
966        * ?++( const volatile T * _Atomic restrict volatile * );
967forall( otype T ) restrict volatile T * ?++( restrict volatile T * restrict volatile * ),
968        * ?++( restrict volatile T * _Atomic restrict volatile * );
969forall( otype T ) _Atomic const restrict T * ?++( _Atomic const restrict T * restrict volatile * ),
970        * ?++( _Atomic const restrict T * _Atomic restrict volatile * );
971forall( otype T ) _Atomic const volatile T * ?++( _Atomic const volatile T * restrict volatile * ),
972        * ?++( _Atomic const volatile T * _Atomic restrict volatile * );
973forall( otype T ) _Atomic restrict volatile T * ?++( _Atomic restrict volatile T * restrict volatile * ),
974        * ?++( _Atomic restrict volatile T * _Atomic restrict volatile * );
975forall( otype T ) const restrict volatile T * ?++( const restrict volatile T * restrict volatile * ),
976        * ?++( const restrict volatile T * _Atomic restrict volatile * );
977forall( otype T ) _Atomic const restrict volatile T * ?++( _Atomic const restrict volatile T * restrict volatile * ),
978        * ?++( _Atomic const restrict volatile T * _Atomic restrict volatile * );
979
980_Bool ?--( volatile _Bool * ), ?--( _Atomic volatile _Bool * );
981char ?--( volatile char * ), ?--( _Atomic volatile char * );
982signed char ?--( volatile signed char * ), ?--( _Atomic volatile signed char * );
983unsigned char ?--( volatile signed char * ), ?--( _Atomic volatile signed char * );
984short int ?--( volatile short int * ), ?--( _Atomic volatile short int * );
985unsigned short int ?--( volatile unsigned short int * ), ?--( _Atomic volatile unsigned short int * );
986int ?--( volatile int * ), ?--( _Atomic volatile int * );
987unsigned int ?--( volatile unsigned int * ), ?--( _Atomic volatile unsigned int * );
988long int ?--( volatile long int * ), ?--( _Atomic volatile long int * );
989long unsigned int ?--( volatile long unsigned int * ), ?--( _Atomic volatile long unsigned int * );
990long long int ?--( volatile long long int * ), ?--( _Atomic volatile long long int * );
991long long unsigned ?--( volatile long long unsigned int * ), ?--( _Atomic volatile long long unsigned int * );
992float ?--( volatile float * ), ?--( _Atomic volatile float * );
993double ?--( volatile double * ), ?--( _Atomic volatile double * );
994long double ?--( volatile long double * ), ?--( _Atomic volatile long double * );
995
996forall( otype T ) T * ?--( T * restrict volatile * ), * ?--( T * _Atomic restrict volatile * );
997forall( otype T ) _Atomic T * ?--( _Atomic T * restrict volatile * ), * ?--( _Atomic T * _Atomic restrict volatile * );
998forall( otype T ) const T * ?--( const T * restrict volatile * ), * ?--( const T * _Atomic restrict volatile * );
999forall( otype T ) volatile T * ?--( volatile T * restrict volatile * ), * ?--( volatile T * _Atomic restrict volatile * );
1000forall( otype T ) restrict T * ?--( restrict T * restrict volatile * ), * ?--( restrict T * _Atomic restrict volatile * );
1001forall( otype T ) _Atomic const T * ?--( _Atomic const T * restrict volatile * ),
1002        * ?--( _Atomic const T * _Atomic restrict volatile * );
1003forall( otype T ) _Atomic restrict T * ?--( _Atomic restrict T * restrict volatile * ),
1004        * ?--( _Atomic restrict T * _Atomic restrict volatile * );
1005forall( otype T ) _Atomic volatile T * ?--( _Atomic volatile T * restrict volatile * ),
1006        * ?--( _Atomic volatile T * _Atomic restrict volatile * );
1007forall( otype T ) const restrict T * ?--( const restrict T * restrict volatile * ),
1008        * ?--( const restrict T * _Atomic restrict volatile * );
1009forall( otype T ) const volatile T * ?--( const volatile T * restrict volatile * ),
1010        * ?--( const volatile T * _Atomic restrict volatile * );
1011forall( otype T ) restrict volatile T * ?--( restrict volatile T * restrict volatile * ),
1012        * ?--( restrict volatile T * _Atomic restrict volatile * );
1013forall( otype T ) _Atomic const restrict T * ?--( _Atomic const restrict T * restrict volatile * ),
1014        * ?--( _Atomic const restrict T * _Atomic restrict volatile * );
1015forall( otype T ) _Atomic const volatile T * ?--( _Atomic const volatile T * restrict volatile * ),
1016        * ?--( _Atomic const volatile T * _Atomic restrict volatile * );
1017forall( otype T ) _Atomic restrict volatile T * ?--( _Atomic restrict volatile T * restrict volatile * ),
1018        * ?--( _Atomic restrict volatile T * _Atomic restrict volatile * );
1019forall( otype T ) const restrict volatile T * ?--( const restrict volatile T * restrict volatile * ),
1020        * ?--( const restrict volatile T * _Atomic restrict volatile * );
1021forall( otype T ) _Atomic const restrict volatile T * ?--( _Atomic const restrict volatile T * restrict volatile * ),
1022        * ?--( _Atomic const restrict volatile T * _Atomic restrict volatile * );
1023\end{lstlisting}
1024For every extended integer type ©X© there exist
1025% Don't use predefined: keep this out of prelude.cf.
1026\begin{lstlisting}
1027X ?++( volatile X * ), ?++( _Atomic volatile X * ),
1028  ?--( volatile X * ), ?--( _Atomic volatile X * );
1029\end{lstlisting}
1030For every complete enumerated type ©E© there exist
1031% Don't use predefined: keep this out of prelude.cf.
1032\begin{lstlisting}
1033E ?++( volatile E * ), ?++( _Atomic volatile E * ),
1034  ?--( volatile E * ), ?--( _Atomic volatile E * );
1035\end{lstlisting}
1036
1037\begin{rationale}
1038Note that ``©++©'' and ``©--©'' 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.
1039This partially enforces the C semantic rule that such operands must be \emph{modifiable} lvalues.
1040\end{rationale}
1041
1042\begin{rationale}
1043In C, a semantic rule requires that pointer operands of increment and decrement be pointers to object types.
1044Hence, ©void *© objects cannot be incremented.
1045In \CFA, the restriction follows from the use of a ©type© parameter in the predefined function definitions, as opposed to ©dtype©, since only object types can be inferred arguments corresponding to the type parameter ©T©.
1046\end{rationale}
1047
1048\semantics
1049First, each interpretation of the operand of an increment or decrement expression is considered separately.
1050For 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.
1051
1052For the remaining interpretations, the expression is rewritten, and the interpretations of the expression are the interpretations of the corresponding function call.
1053Finally, all interpretations of the expression produced for the different interpretations of the operand are combined to produce the interpretations of the expression as a whole; where interpretations have compatible result types, the best interpretations are selected in the manner described for function call expressions.
1054
1055\examples
1056\begin{lstlisting}
1057volatile short int vs;  vs++; // rewritten as ?++( &(vs) )
1058short int s;                    s++;
1059const short int cs;             cs++;
1060_Atomic short int as;   as++;
1061\end{lstlisting}
1062\begin{sloppypar}
1063Since ©&(vs)© has type ©volatile short int *©, the best valid interpretation of ©vs++© calls the ©?++© function with the ©volatile short *© parameter.
1064©s++© does the same, applying the safe conversion from ©short int *© to ©volatile short int *©.
1065Note that there is no conversion that adds an ©_Atomic© qualifier, so the ©_Atomic volatile short int© overloading does not provide a valid interpretation.
1066\end{sloppypar}
1067
1068There is no safe conversion from ©const short int *© to ©volatile short int *©, and no ©?++© function that accepts a ©const *© parameter, so ©cs++© has no valid interpretations.
1069
1070The best valid interpretation of ©as++© calls the ©short ?++© function with the ©_Atomic volatile short int *© parameter, applying a safe conversion to add the ©volatile© qualifier.
1071\begin{lstlisting}
1072char * const restrict volatile * restrict volatile pqpc;
1073pqpc++
1074char * * restrict volatile ppc;
1075ppc++;
1076\end{lstlisting}
1077Since ©&(pqpc)© has type ©char * const restrict volatile * restrict volatile *©, the best valid interpretation of ©pqpc++© calls the polymorphic ©?++© function with the ©const restrict volatile T * restrict volatile *© parameter, inferring ©T© to be ©char *©.
1078
1079©ppc++© calls the same function, again inferring ©T© to be ©char *©, and using the safe conversions from ©T© to ©T const© ©restrict volatile©.
1080
1081\begin{rationale}
1082Increment and decrement expressions show up a deficiency of \CFA's type system.
1083There is no such thing as a pointer to a register object or bit-field\index{deficiencies!pointers to bit-fields}.
1084Therefore, there is no way to define a function that alters them, and hence no way to define increment and decrement functions for them.
1085As a result, the semantics of increment and decrement expressions must treat them specially.
1086This holds true for all of the operators that may modify such objects.
1087\end{rationale}
1088
1089\begin{rationale}
1090The polymorphic overloadings for pointer increment and decrement can be understood by considering increasingly complex types.
1091\begin{enumerate}
1092\item
1093``©char * p; p++;©''.
1094The argument to ©?++© has type ©char * *©, and the result has type ©char *©.
1095The expression would be valid if ©?++© were declared by
1096\begin{lstlisting}
1097forall( otype T ) T * ?++( T * * );
1098\end{lstlisting} with ©T© inferred to be ©char©.
1099
1100\item
1101``©char *restrict volatile qp; qp++©''.
1102The result again has type ©char *©, but the argument now has type ©char *restrict volatile *©, so it cannot be passed to the hypothetical function declared in point 1.
1103Hence the actual predefined function is
1104\begin{lstlisting}
1105forall( otype T ) T * ?++( T * restrict volatile * );
1106\end{lstlisting} which also accepts a ©char * *© argument, because of the safe conversions that add ©volatile© and ©restrict© qualifiers. (The parameter is not const-qualified, so constant pointers cannot be incremented.)
1107
1108\item
1109``©char *_Atomic ap; ap++©''.
1110The result again has type ©char *©, but no safe conversion adds an ©_Atomic© qualifier, so the function in point 2 is not applicable.
1111A separate overloading of ©?++© is required.
1112
1113\item
1114``©char const volatile * pq; pq++©''.
1115Here the result has type ©char const volatile *©, so a new overloading is needed:
1116\begin{lstlisting}
1117forall( otype T ) T const volatile * ?++( T const volatile *restrict volatile * );
1118\end{lstlisting}
1119One overloading is needed for each combination of qualifiers in the pointed-at type\index{deficiencies!pointers to qualified types}.
1120 
1121\item
1122``©float *restrict * prp; prp++©''.
1123The ©restrict© qualifier is handled just like ©const© and ©volatile© in the previous case:
1124\begin{lstlisting}
1125forall( otype T ) T restrict * ?++( T restrict *restrict volatile * );
1126\end{lstlisting} with ©T© inferred to be ©float *©.
1127This looks odd, because \Celeven contains a constraint that requires restrict-qualified types to be pointer-to-object types, and ©T© is not syntactically a pointer type. \CFA loosens the constraint.
1128\end{enumerate}
1129\end{rationale}
1130
1131
1132\subsubsection{Compound literals}
1133
1134\semantics 
1135A compound literal has one interpretation, with the type given by the \nonterm{type-name} of the compound literal.
1136
1137
1138\subsection{Unary operators}
1139
1140\begin{syntax}
1141\lhs{unary-expression}
1142        \rhs \nonterm{postfix-expression}
1143        \rhs ©++© \nonterm{unary-expression}
1144        \rhs ©--© \nonterm{unary-expression}
1145        \rhs \nonterm{unary-operator} \nonterm{cast-expression}
1146        \rhs ©sizeof© \nonterm{unary-expression}
1147        \rhs ©sizeof© ©(© \nonterm{type-name} ©)©
1148\lhs{unary-operator} one of
1149        \rhs ©&© ©*© ©+© ©-© ©~© ©!©
1150\end{syntax}
1151
1152\rewriterules
1153\begin{lstlisting}
1154*a      => *?( a )§\use{*?}§
1155+a      => +?( a )§\use{+?}§
1156-a      => -?( a )§\use{-?}§
1157~a      => ~?( a )§\use{~?}§
1158!a      => !?( a )§\use{"!?}§
1159++a     => ++?(&( a ))§\use{++?}§
1160--a     => --?(&( a ))§\use{--?}§
1161\end{lstlisting}
1162
1163
1164\subsubsection{Prefix increment and decrement operators}
1165
1166\predefined
1167\begin{lstlisting}
1168_Bool ++?( volatile _Bool * ), ++?( _Atomic volatile _Bool * );
1169char ++?( volatile char * ), ++?( _Atomic volatile char * );
1170signed char ++?( volatile signed char * ), ++?( _Atomic volatile signed char * );
1171unsigned char ++?( volatile signed char * ), ++?( _Atomic volatile signed char * );
1172short int ++?( volatile short int * ), ++?( _Atomic volatile short int * );
1173unsigned short int ++?( volatile unsigned short int * ), ++?( _Atomic volatile unsigned short int * );
1174int ++?( volatile int * ), ++?( _Atomic volatile int * );
1175unsigned int ++?( volatile unsigned int * ), ++?( _Atomic volatile unsigned int * );
1176long int ++?( volatile long int * ), ++?( _Atomic volatile long int * );
1177long unsigned int ++?( volatile long unsigned int * ), ++?( _Atomic volatile long unsigned int * );
1178long long int ++?( volatile long long int * ), ++?( _Atomic volatile long long int * );
1179long long unsigned ++?( volatile long long unsigned int * ), ++?( _Atomic volatile long long unsigned int * );
1180float ++?( volatile float * ), ++?( _Atomic volatile float * );
1181double ++?( volatile double * ), ++?( _Atomic volatile double * );
1182long double ++?( volatile long double * ), ++?( _Atomic volatile long double * );
1183
1184forall( otype T ) T * ++?( T * restrict volatile * ), * ++?( T * _Atomic restrict volatile * );
1185forall( otype T ) _Atomic T * ++?( _Atomic T * restrict volatile * ), * ++?( _Atomic T * _Atomic restrict volatile * );
1186forall( otype T ) const T * ++?( const T * restrict volatile * ), * ++?( const T * _Atomic restrict volatile * );
1187forall( otype T ) volatile T * ++?( volatile T * restrict volatile * ), * ++?( volatile T * _Atomic restrict volatile * );
1188forall( otype T ) restrict T * ++?( restrict T * restrict volatile * ), * ++?( restrict T * _Atomic restrict volatile * );
1189forall( otype T ) _Atomic const T * ++?( _Atomic const T * restrict volatile * ),
1190        * ++?( _Atomic const T * _Atomic restrict volatile * );
1191forall( otype T ) _Atomic volatile T * ++?( _Atomic volatile T * restrict volatile * ),
1192        * ++?( _Atomic volatile T * _Atomic restrict volatile * );
1193forall( otype T ) _Atomic restrict T * ++?( _Atomic restrict T * restrict volatile * ),
1194        * ++?( _Atomic restrict T * _Atomic restrict volatile * );
1195forall( otype T ) const volatile T * ++?( const volatile T * restrict volatile * ),
1196        * ++?( const volatile T * _Atomic restrict volatile * );
1197forall( otype T ) const restrict T * ++?( const restrict T * restrict volatile * ),
1198        * ++?( const restrict T * _Atomic restrict volatile * );
1199forall( otype T ) restrict volatile T * ++?( restrict volatile T * restrict volatile * ),
1200        * ++?( restrict volatile T * _Atomic restrict volatile * );
1201forall( otype T ) _Atomic const volatile T * ++?( _Atomic const volatile T * restrict volatile * ),
1202        * ++?( _Atomic const volatile T * _Atomic restrict volatile * );
1203forall( otype T ) _Atomic const restrict T * ++?( _Atomic const restrict T * restrict volatile * ),
1204        * ++?( _Atomic const restrict T * _Atomic restrict volatile * );
1205forall( otype T ) _Atomic restrict volatile T * ++?( _Atomic restrict volatile T * restrict volatile * ),
1206        * ++?( _Atomic restrict volatile T * _Atomic restrict volatile * );
1207forall( otype T ) const restrict volatile T * ++?( const restrict volatile T * restrict volatile * ),
1208        * ++?( const restrict volatile T * _Atomic restrict volatile * );
1209forall( otype T ) _Atomic const restrict volatile T * ++?( _Atomic const restrict volatile T * restrict volatile * ),
1210        * ++?( _Atomic const restrict volatile T * _Atomic restrict volatile * );
1211
1212_Bool --?( volatile _Bool * ), --?( _Atomic volatile _Bool * );
1213char --?( volatile char * ), --?( _Atomic volatile char * );
1214signed char --?( volatile signed char * ), --?( _Atomic volatile signed char * );
1215unsigned char --?( volatile signed char * ), --?( _Atomic volatile signed char * );
1216short int --?( volatile short int * ), --?( _Atomic volatile short int * );
1217unsigned short int --?( volatile unsigned short int * ), --?( _Atomic volatile unsigned short int * );
1218int --?( volatile int * ), --?( _Atomic volatile int * );
1219unsigned int --?( volatile unsigned int * ), --?( _Atomic volatile unsigned int * );
1220long int --?( volatile long int * ), --?( _Atomic volatile long int * );
1221long unsigned int --?( volatile long unsigned int * ), --?( _Atomic volatile long unsigned int * );
1222long long int --?( volatile long long int * ), --?( _Atomic volatile long long int * );
1223long long unsigned --?( volatile long long unsigned int * ), --?( _Atomic volatile long long unsigned int * );
1224float --?( volatile float * ), --?( _Atomic volatile float * );
1225double --?( volatile double * ), --?( _Atomic volatile double * );
1226long double --?( volatile long double * ), --?( _Atomic volatile long double * );
1227
1228forall( otype T ) T * --?( T * restrict volatile * ), * --?( T * _Atomic restrict volatile * );
1229forall( otype T ) _Atomic T * --?( _Atomic T * restrict volatile * ), * --?( _Atomic T * _Atomic restrict volatile * );
1230forall( otype T ) const T * --?( const T * restrict volatile * ), * --?( const T * _Atomic restrict volatile * );
1231forall( otype T ) volatile T * --?( volatile T * restrict volatile * ), * --?( volatile T * _Atomic restrict volatile * );
1232forall( otype T ) restrict T * --?( restrict T * restrict volatile * ), * --?( restrict T * _Atomic restrict volatile * );
1233forall( otype T ) _Atomic const T * --?( _Atomic const T * restrict volatile * ),
1234        * --?( _Atomic const T * _Atomic restrict volatile * );
1235forall( otype T ) _Atomic volatile T * --?( _Atomic volatile T * restrict volatile * ),
1236        * --?( _Atomic volatile T * _Atomic restrict volatile * );
1237forall( otype T ) _Atomic restrict T * --?( _Atomic restrict T * restrict volatile * ),
1238        * --?( _Atomic restrict T * _Atomic restrict volatile * );
1239forall( otype T ) const volatile T * --?( const volatile T * restrict volatile * ),
1240        * --?( const volatile T * _Atomic restrict volatile * );
1241forall( otype T ) const restrict T * --?( const restrict T * restrict volatile * ),
1242        * --?( const restrict T * _Atomic restrict volatile * );
1243forall( otype T ) restrict volatile T * --?( restrict volatile T * restrict volatile * ),
1244        * --?( restrict volatile T * _Atomic restrict volatile * );
1245forall( otype T ) _Atomic const volatile T * --?( _Atomic const volatile T * restrict volatile * ),
1246        * --?( _Atomic const volatile T * _Atomic restrict volatile * );
1247forall( otype T ) _Atomic const restrict T * --?( _Atomic const restrict T * restrict volatile * ),
1248        * --?( _Atomic const restrict T * _Atomic restrict volatile * );
1249forall( otype T ) _Atomic restrict volatile T * --?( _Atomic restrict volatile T * restrict volatile * ),
1250        * --?( _Atomic restrict volatile T * _Atomic restrict volatile * );
1251forall( otype T ) const restrict volatile T * --?( const restrict volatile T * restrict volatile * ),
1252        * --?( const restrict volatile T * _Atomic restrict volatile * );
1253forall( otype T ) _Atomic const restrict volatile T * --?( _Atomic const restrict volatile T * restrict volatile * ),
1254        * --?( _Atomic const restrict volatile T * _Atomic restrict volatile * );
1255\end{lstlisting}
1256For every extended integer type ©X© there exist
1257% Don't use predefined: keep this out of prelude.cf.
1258\begin{lstlisting}
1259X       ++?( volatile X * ),
1260        ++?( _Atomic volatile X * ),
1261        --?( volatile X * ),
1262        --?( _Atomic volatile X * );
1263\end{lstlisting}
1264For every complete enumerated type ©E© there exist
1265% Don't use predefined: keep this out of prelude.cf.
1266\begin{lstlisting}
1267E ++?( volatile E * ),
1268        ++?( _Atomic volatile E * ),
1269        ?--( volatile E * ),
1270        ?--( _Atomic volatile E * );
1271\end{lstlisting}
1272
1273\semantics
1274The interpretations of prefix increment and decrement expressions are determined in the same way as the interpretations of postfix increment and decrement expressions.
1275
1276
1277\subsubsection{Address and indirection operators}
1278
1279\predefined
1280\begin{lstlisting}
1281forall( otype T ) lvalue T *?( T * );
1282forall( otype T ) _Atomic lvalue T *?( _Atomic T * );
1283forall( otype T ) const lvalue T *?( const T * );
1284forall( otype T ) volatile lvalue T *?( volatile T * );
1285forall( otype T ) restrict lvalue T *?( restrict T * );
1286forall( otype T ) _Atomic const lvalue T *?( _Atomic const T * );
1287forall( otype T ) _Atomic volatile lvalue T *?( _Atomic volatile T * );
1288forall( otype T ) _Atomic restrict lvalue T *?( _Atomic restrict T * );
1289forall( otype T ) const volatile lvalue T *?( const volatile T * );
1290forall( otype T ) const restrict lvalue T *?( const restrict T * );
1291forall( otype T ) restrict volatile lvalue T *?( restrict volatile T * );
1292forall( otype T ) _Atomic const volatile lvalue T *?( _Atomic const volatile T * );
1293forall( otype T ) _Atomic const restrict lvalue T *?( _Atomic const restrict T * );
1294forall( otype T ) _Atomic restrict volatile lvalue T *?( _Atomic restrict volatile T * );
1295forall( otype T ) const restrict volatile lvalue T *?( const restrict volatile T * );
1296forall( otype T ) _Atomic const restrict volatile lvalue T *?( _Atomic const restrict volatile T * );
1297forall( ftype FT ) FT *?( FT * );
1298\end{lstlisting}
1299
1300\constraints
1301The operand of the unary ``©&©'' operator shall have exactly one \Index{interpretation}\index{ambiguous interpretation}, which shall be unambiguous.
1302
1303\semantics
1304The ``©&©'' expression has one interpretation which is of type ©T *©, where ©T© is the type of the operand.
1305
1306The interpretations of an indirection expression are the interpretations of the corresponding function call.
1307
1308
1309\subsubsection{Unary arithmetic operators}
1310
1311\predefined
1312\begin{lstlisting}
1313int     +?( int ), -?( int ), ~?( int );
1314unsigned int +?( unsigned int ), -?( unsigned int ), ~?( unsigned int );
1315long int +?( long int ), -?( long int ), ~?( long int );
1316long unsigned int +?( long unsigned int ), -?( long unsigned int ), ~?( long unsigned int );
1317long long int +?( long long int ), -?( long long int ), ~?( long long int );
1318long long unsigned int +?( long long unsigned int ), -?( long long unsigned int ), ~?( long long unsigned int );
1319float +?( float ), -?( float );
1320double +?( double ), -?( double );
1321long double +?( long double ), -?( long double );
1322_Complex float +?( _Complex float ), -?( _Complex float );
1323_Complex double +?( _Complex double ), -?( _Complex double );
1324_Complex long double +?( _Complex long double ), -?( _Complex long double );
1325int !?( int ), !?( unsigned int ), !?( long ), !?( long unsigned int ),
1326        !?( long long int ), !?( long long unsigned int ),
1327        !?( float ), !?( double ), !?( long double ),
1328        !?( _Complex float ), !?( _Complex double ), !?( _Complex long double );
1329forall( dtype DT ) int !?( const restrict volatile DT * );
1330forall( dtype DT ) int !?( _Atomic const restrict volatile DT * );
1331forall( ftype FT ) int !?( FT * );
1332\end{lstlisting}
1333For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int© there exist
1334% Don't use predefined: keep this out of prelude.cf.
1335\begin{lstlisting}
1336X +?( X ), -?( X ), ~?( X );
1337int !?( X );
1338\end{lstlisting}
1339
1340\semantics
1341The interpretations of a unary arithmetic expression are the interpretations of the corresponding function call.
1342
1343\examples
1344\begin{lstlisting}
1345long int li;
1346void eat_double( double );§\use{eat_double}§
1347eat_double(-li ); // => eat_double( -?( li ) );
1348\end{lstlisting}
1349The valid interpretations of ``©-li©'' (assuming no extended integer types exist) are
1350\begin{center}
1351\begin{tabular}{llc} interpretation & result type & expression conversion cost \\
1352\hline
1353©-?( (int)li )©                                         & ©int©                                         & (unsafe) \\
1354©-?( (unsigned)li)©                                     & ©unsigned int©                        & (unsafe) \\
1355©-?( (long)li)©                                         & ©long©                                        & 0 \\
1356©-?( (long unsigned int)li)©            & ©long unsigned int©           & 1 \\
1357©-?( (long long int)li)©                        & ©long long int©                       & 2 \\
1358©-?( (long long unsigned int)li)©       & ©long long unsigned int©      & 3 \\
1359©-?( (float)li)©                                        & ©float©                                       & 4 \\
1360©-?( (double)li)©                                       & ©double©                                      & 5 \\
1361©-?( (long double)li)©                          & ©long double©                         & 6 \\
1362©-?( (_Complex float)li)©                       & ©float©                                       & (unsafe) \\
1363©-?( (_Complex double)li)©                      & ©double©                                      & (unsafe) \\
1364©-?( (_Complex long double)li)©         & ©long double©                         & (unsafe) \\
1365\end{tabular}
1366\end{center}
1367The valid interpretations of the ©eat_double© call, with the cost of the argument conversion and the cost of the entire expression, are
1368\begin{center}
1369\begin{tabular}{lcc} interpretation & argument cost & expression cost \\
1370\hline
1371©eat_double( (double)-?( (int)li) )©                                    & 7                     & (unsafe) \\
1372©eat_double( (double)-?( (unsigned)li) )©                               & 6                     & (unsafe) \\
1373©eat_double( (double)-?(li) )©                                                  & 5                     & \(0+5=5\) \\
1374©eat_double( (double)-?( (long unsigned int)li) )©              & 4                     & \(1+4=5\) \\
1375©eat_double( (double)-?( (long long int)li) )©                  & 3                     & \(2+3=5\) \\
1376©eat_double( (double)-?( (long long unsigned int)li) )© & 2                     & \(3+2=5\) \\
1377©eat_double( (double)-?( (float)li) )©                                  & 1                     & \(4+1=5\) \\
1378©eat_double( (double)-?( (double)li) )©                                 & 0                     & \(5+0=5\) \\
1379©eat_double( (double)-?( (long double)li) )©                    & (unsafe)      & (unsafe) \\
1380©eat_double( (double)-?( (_Complex float)li) )©                 & (unsafe)      & (unsafe) \\
1381©eat_double( (double)-?( (_Complex double)li) )©                & (unsafe)      & (unsafe) \\
1382©eat_double( (double)-?( (_Complex long double)li) )©   & (unsafe)      & (unsafe) \\
1383\end{tabular}
1384\end{center}
1385Each has result type ©void©, so the best must be selected.
1386The interpretations involving unsafe conversions are discarded.
1387The remainder have equal expression conversion costs, so the ``highest argument conversion cost'' rule is invoked, and the chosen interpretation is ©eat_double( (double)-?(li) )©.
1388
1389
1390\subsubsection[The sizeof and \_Alignof operators]{The \lstinline@sizeof@ and \lstinline@_Alignof@ operators}
1391
1392\constraints
1393The operand of ©sizeof© or ©_Alignof© shall not be ©type©, ©dtype©, or ©ftype©.
1394
1395When the ©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 ©sizeof© or ©_Alignof© expression has one interpretation, of type ©size_t©.
1396
1397When ©sizeof© is applied to an identifier declared by a \nonterm{type-declaration} or a
1398\nonterm{type-parameter}, it yields the size in bytes of the type that implements the operand.
1399When the operand is an opaque type or an inferred type parameter\index{inferred parameter}, the expression is not a constant expression.
1400
1401When ©_Alignof© is applied to an identifier declared by a \nonterm{type-declaration} or a
1402\nonterm{type-parameter}, it yields the alignment requirement of the type that implements the operand.
1403When the operand is an opaque type or an inferred type parameter\index{inferred parameter}, the expression is not a constant expression.
1404\begin{rationale}
1405\begin{lstlisting}
1406otype Pair = struct { int first, second; };
1407size_t p_size = sizeof(Pair);           // constant expression
1408extern otype Rational;§\use{Rational}§
1409size_t c_size = sizeof(Rational);       // non-constant expression
1410forall(type T) T f(T p1, T p2) {
1411        size_t t_size = sizeof(T);              // non-constant expression
1412        ...
1413}
1414\end{lstlisting}
1415``©sizeof Rational©'', although not statically known, is fixed.
1416Within ©f()©, ``©sizeof(T)©'' is fixed for each call of ©f()©, but may vary from call to call.
1417\end{rationale}
1418
1419
1420\subsection{Cast operators}
1421
1422\begin{syntax}
1423\lhs{cast-expression}
1424\rhs \nonterm{unary-expression}
1425\rhs ©(© \nonterm{type-name} ©)© \nonterm{cast-expression}
1426\end{syntax}
1427
1428\constraints
1429The \nonterm{type-name} in a \nonterm{cast-expression} shall not be ©type©, ©dtype©, or ©ftype©.
1430
1431\semantics
1432
1433In a \Index{cast expression} ``©(©\nonterm{type-name}©)e©'', if
1434\nonterm{type-name} is the type of an interpretation of ©e©, then that interpretation is the only interpretation of the cast expression;
1435otherwise, ©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.
1436The 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.
1437
1438\begin{rationale}
1439Casts can be used to eliminate ambiguity in expressions by selecting interpretations of subexpressions, and to specialize polymorphic functions and values.
1440\end{rationale}
1441
1442
1443\subsection{Multiplicative operators}
1444
1445\begin{syntax}
1446\lhs{multiplicative-expression}
1447\rhs \nonterm{cast-expression}
1448\rhs \nonterm{multiplicative-expression} ©*© \nonterm{cast-expression}
1449\rhs \nonterm{multiplicative-expression} ©/© \nonterm{cast-expression}
1450\rhs \nonterm{multiplicative-expression} ©%© \nonterm{cast-expression}
1451\end{syntax}
1452
1453\rewriterules
1454\begin{lstlisting}
1455a * b => ?*?( a, b )§\use{?*?}§
1456a / b => ?/?( a, b )§\use{?/?}§
1457a % b => ?%?( a, b )§\use{?%?}§
1458\end{lstlisting}
1459
1460\predefined
1461\begin{lstlisting}
1462int?*?( int, int ), ?/?( int, int ), ?%?( int, int );
1463unsigned int?*?( unsigned int, unsigned int ), ?/?( unsigned int, unsigned int ), ?%?( unsigned int, unsigned int );
1464long int?*?( long int, long int ), ?/?( long, long ), ?%?( long, long );
1465long unsigned int?*?( long unsigned int, long unsigned int ),
1466        ?/?( long unsigned int, long unsigned int ), ?%?( long unsigned int, long unsigned int );
1467long long int?*?( long long int, long long int ), ?/?( long long int, long long int ),
1468        ?%?( long long int, long long int );
1469long long unsigned int ?*?( long long unsigned int, long long unsigned int ),
1470        ?/?( long long unsigned int, long long unsigned int ), ?%?( long long unsigned int, long long unsigned int );
1471float?*?( float, float ), ?/?( float, float );
1472double?*?( double, double ), ?/?( double, double );
1473long double?*?( long double, long double ), ?/?( long double, long double );
1474_Complex float?*?( float, _Complex float ), ?/?( float, _Complex float ),
1475        ?*?( _Complex float, float ), ?/?( _Complex float, float ),
1476        ?*?( _Complex float, _Complex float ), ?/?( _Complex float, _Complex float );
1477_Complex double?*?( double, _Complex double ), ?/?( double, _Complex double ),
1478        ?*?( _Complex double, double ), ?/?( _Complex double, double ),
1479        ?*?( _Complex double, _Complex double ), ?/?( _Complex double, _Complex double );
1480_Complex long double?*?( long double, _Complex long double ), ?/?( long double, _Complex long double ),
1481        ?*?( _Complex long double, long double ), ?/?( _Complex long double, long double ),
1482        ?*?( _Complex long double, _Complex long double ), ?/?( _Complex long double, _Complex long double );
1483\end{lstlisting}
1484For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int© there exist
1485% Don't use predefined: keep this out of prelude.cf.
1486\begin{lstlisting}
1487X ?*?( X ), ?/?( X ), ?%?( X );
1488\end{lstlisting}
1489
1490\begin{rationale}
1491\Celeven does not include conversions from the \Index{real type}s to \Index{complex type}s in the \Index{usual arithmetic conversion}s.  Instead it specifies conversion of the result of binary operations on arguments from mixed type domains. \CFA's predefined operators match that pattern.
1492\end{rationale}
1493
1494\semantics
1495The interpretations of multiplicative expressions are the interpretations of the corresponding function call.
1496
1497\examples
1498\begin{lstlisting}
1499int i;
1500long li;
1501void eat_double( double );§\use{eat_double}§
1502eat_double( li % i );
1503\end{lstlisting}
1504``©li % i©'' is rewritten as ``©?%?(li, i )©''.
1505The valid interpretations of ©?%?(li, i )©, the cost\index{conversion cost} of converting their arguments, and the cost of converting the result to ©double© (assuming no extended integer types are present ) are
1506\begin{center}
1507\begin{tabular}{lcc} interpretation & argument cost & result cost \\
1508\hline
1509© ?%?( (int)li, i )©                                                                            & (unsafe)      & 6     \\
1510© ?%?( (unsigned)li,(unsigned)i )©                                                      & (unsafe)      & 5     \\
1511© ?%?( li, (long)i )©                                                                           & 1                     & 4     \\
1512© ?%?( (long unsigned)li,(long unsigned)i )©                            & 3                     & 3     \\
1513© ?%?( (long long)li,(long long)i )©                                            & 5                     & 2     \\
1514© ?%?( (long long unsigned)li, (long long unsigned)i )©         & 7                     & 1     \\
1515\end{tabular}
1516\end{center}
1517The best interpretation of ©eat_double( li, i )© is ©eat_double( (double)?%?(li, (long)i ))©, which has no unsafe conversions and the lowest total cost.
1518
1519\begin{rationale}
1520\Celeven 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 ©int©.
1521If ©s© is a ©short int©, ``©s *s©'' does not have type ©short int©;
1522it is treated as ``©( (int)s ) * ( (int)s )©'', and has type ©int©. \CFA matches that pattern;
1523it does not predefine ``©short ?*?( short, short )©''.
1524
1525These ``missing'' operators limit polymorphism.
1526Consider
1527\begin{lstlisting}
1528forall( otype T | T ?*?( T, T ) ) T square( T );
1529short s;
1530square( s );
1531\end{lstlisting}
1532Since \CFA does not define a multiplication operator for ©short int©, ©square( s )© is treated as ©square( (int)s )©, and the result has type ©int©.
1533This is mildly surprising, but it follows the \Celeven operator pattern.
1534
1535A more troubling example is
1536\begin{lstlisting}
1537forall( otype T | ?*?( T, T ) ) T product( T[], int n );
1538short sa[5];
1539product( sa, 5);
1540\end{lstlisting}
1541This has no valid interpretations, because \CFA has no conversion from ``array of ©short int©'' to ``array of ©int©''.
1542The alternatives in such situations include
1543\begin{itemize}
1544\item
1545Defining monomorphic overloadings of ©product© for ©short© and the other ``small'' types.
1546\item
1547Defining ``©short ?*?( short, short )©'' within the scope containing the call to ©product©.
1548\item
1549Defining ©product© to take as an argument a conversion function from the ``small'' type to the operator's argument type.
1550\end{itemize}
1551\end{rationale}
1552
1553
1554\subsection{Additive operators}
1555
1556\begin{syntax}
1557\lhs{additive-expression}
1558\rhs \nonterm{multiplicative-expression}
1559\rhs \nonterm{additive-expression} ©+© \nonterm{multiplicative-expression}
1560\rhs \nonterm{additive-expression} ©-© \nonterm{multiplicative-expression}
1561\end{syntax}
1562
1563\rewriterules
1564\begin{lstlisting}
1565a + b => ?+?( a, b )§\use{?+?}§
1566a - b => ?-?( a, b )§\use{?-?}§
1567\end{lstlisting}
1568
1569\predefined
1570\begin{lstlisting}
1571int?+?( int, int ), ?-?( int, int );
1572unsigned int?+?( unsigned int, unsigned int ), ?-?( unsigned int, unsigned int );
1573long int?+?( long int, long int ), ?-?( long int, long int );
1574long unsigned int?+?( long unsigned int, long unsigned int ), ?-?( long unsigned int, long unsigned int );
1575long long int?+?( long long int, long long int ), ?-?( long long int, long long int );
1576long long unsigned int ?+?( long long unsigned int, long long unsigned int ),
1577        ?-?( long long unsigned int, long long unsigned int );
1578float?+?( float, float ), ?-?( float, float );
1579double?+?( double, double ), ?-?( double, double );
1580long double?+?( long double, long double ), ?-?( long double, long double );
1581_Complex float?+?( _Complex float, float ), ?-?( _Complex float, float ),
1582        ?+?( float, _Complex float ), ?-?( float, _Complex float ),
1583        ?+?( _Complex float, _Complex float ), ?-?( _Complex float, _Complex float );
1584_Complex double?+?( _Complex double, double ), ?-?( _Complex double, double ),
1585        ?+?( double, _Complex double ), ?-?( double, _Complex double ),
1586        ?+?( _Complex double, _Complex double ), ?-?( _Complex double, _Complex double );
1587_Complex long double?+?( _Complex long double, long double ), ?-?( _Complex long double, long double ),
1588        ?+?( long double, _Complex long double ), ?-?( long double, _Complex long double ),
1589        ?+?( _Complex long double, _Complex long double ), ?-?( _Complex long double, _Complex long double );
1590
1591forall( otype T ) T * ?+?( T *, ptrdiff_t ), * ?+?( ptrdiff_t, T * ), * ?-?( T *, ptrdiff_t );
1592forall( otype T ) _Atomic T * ?+?( _Atomic T *, ptrdiff_t ), * ?+?( ptrdiff_t, _Atomic T * ),
1593        * ?-?( _Atomic T *, ptrdiff_t );
1594forall( otype T ) const T * ?+?( const T *, ptrdiff_t ), * ?+?( ptrdiff_t, const T * ),
1595        * ?-?( const T *, ptrdiff_t );
1596forall( otype T ) restrict T * ?+?( restrict T *, ptrdiff_t ), * ?+?( ptrdiff_t, restrict T * ),
1597        * ?-?( restrict T *, ptrdiff_t );
1598forall( otype T ) volatile T * ?+?( volatile T *, ptrdiff_t ), * ?+?( ptrdiff_t, volatile T * ),
1599        * ?-?( volatile T *, ptrdiff_t );
1600forall( otype T ) _Atomic const T * ?+?( _Atomic const T *, ptrdiff_t ), * ?+?( ptrdiff_t, _Atomic const T * ),
1601        * ?-?( _Atomic const T *, ptrdiff_t );
1602forall( otype T ) _Atomic restrict T * ?+?( _Atomic restrict T *, ptrdiff_t ), * ?+?( ptrdiff_t, _Atomic restrict T * ),
1603        * ?-?( _Atomic restrict T *, ptrdiff_t );
1604forall( otype T ) _Atomic volatile T * ?+?( _Atomic volatile T *, ptrdiff_t ), * ?+?( ptrdiff_t, _Atomic volatile T * ),
1605        * ?-?( _Atomic volatile T *, ptrdiff_t );
1606forall( otype T ) const restrict T * ?+?( const restrict T *, ptrdiff_t ), * ?+?( ptrdiff_t, const restrict T * ),
1607        * ?-?( const restrict T *, ptrdiff_t );
1608forall( otype T ) const volatile T * ?+?( const volatile T *, ptrdiff_t ), * ?+?( ptrdiff_t, const volatile T * ),
1609        * ?-?( const volatile T *, ptrdiff_t );
1610forall( otype T ) restrict volatile T * ?+?( restrict volatile T *, ptrdiff_t ), * ?+?( ptrdiff_t, restrict volatile T * ),
1611        * ?-?( restrict volatile T *, ptrdiff_t );
1612forall( otype T ) _Atomic const restrict T * ?+?( _Atomic const restrict T *, ptrdiff_t ),
1613        * ?+?( ptrdiff_t, _Atomic const restrict T * ),
1614        * ?-?( _Atomic const restrict T *, ptrdiff_t );
1615forall( otype T ) ptrdiff_t
1616        * ?-?( const restrict volatile T *, const restrict volatile T * ),
1617        * ?-?( _Atomic const restrict volatile T *, _Atomic const restrict volatile T * );
1618\end{lstlisting}
1619For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int© there exist
1620% Don't use predefined: keep this out of prelude.cf.
1621\begin{lstlisting}
1622X ?+?( X ), ?-?( X );
1623\end{lstlisting}
1624
1625\semantics
1626The interpretations of additive expressions are the interpretations of the corresponding function calls.
1627
1628\begin{rationale}
1629©ptrdiff_t© is an implementation-defined identifier defined in ©<stddef.h>© that is synonymous with a signed integral type that is large enough to hold the difference between two pointers.
1630It 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.
1631The \Celeven standard uses ©size_t© in several cases where a library function takes an argument that is used as a subscript, but ©size_t© is unsuitable here because it is an unsigned type.
1632\end{rationale}
1633
1634
1635\subsection{Bitwise shift operators}
1636
1637\begin{syntax}
1638\lhs{shift-expression}
1639\rhs \nonterm{additive-expression}
1640\rhs \nonterm{shift-expression} ©<<© \nonterm{additive-expression}
1641\rhs \nonterm{shift-expression} ©>>© \nonterm{additive-expression}
1642\end{syntax}
1643
1644\rewriterules
1645\begin{lstlisting}
1646a << b => ?<<?( a, b )§\use{?<<?}§
1647a >> b => ?>>?( a, b )§\use{?>>?}§
1648\end{lstlisting}
1649
1650\predefined
1651\begin{lstlisting}
1652int ?<<?( int, int ), ?>>?( int, int );
1653unsigned int ?<<?( unsigned int, int ), ?>>?( unsigned int, int );
1654long int ?<<?( long int, int ), ?>>?( long int, int );
1655long unsigned int ?<<?( long unsigned int, int ), ?>>?( long unsigned int, int );
1656long long int ?<<?( long long int, int ), ?>>?( long long int, int );
1657long long unsigned int ?<<?( long long unsigned int, int ), ?>>?( long long unsigned int, int);
1658\end{lstlisting}
1659For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int© there exist
1660% Don't use predefined: keep this out of prelude.cf.
1661\begin{lstlisting}
1662X ?<<?( X, int ), ?>>?( X, int );
1663\end{lstlisting}
1664
1665\begin{rationale}
1666The bitwise shift operators break the usual pattern: they do not convert both operands to a common type.
1667The right operand only undergoes \Index{integer promotion}.
1668\end{rationale}
1669
1670\semantics
1671The interpretations of a bitwise shift expression are the interpretations of the corresponding function calls.
1672
1673
1674\subsection{Relational operators}
1675
1676\begin{syntax}
1677\lhs{relational-expression}
1678\rhs \nonterm{shift-expression}
1679\rhs \nonterm{relational-expression} ©< © \nonterm{shift-expression}
1680\rhs \nonterm{relational-expression} ©> © \nonterm{shift-expression}
1681\rhs \nonterm{relational-expression} ©<=© \nonterm{shift-expression}
1682\rhs \nonterm{relational-expression} ©>=© \nonterm{shift-expression}
1683\end{syntax}
1684
1685\rewriterules
1686\begin{lstlisting}
1687a < b => ?<?( a, b )§\use{?<?}§
1688a > b => ?>?( a, b )§\use{?>?}§
1689a <= b => ?<=?( a, b )§\use{?<=?}§
1690a >= b => ?>=?( a, b )§\use{?>=?}§
1691\end{lstlisting}
1692
1693\predefined
1694\begin{lstlisting}
1695int ?<?( int, int ), ?<=?( int, int ),
1696        ?>?( int, int ), ?>=?( int, int );
1697int ?<?( unsigned int, unsigned int ), ?<=?( unsigned int, unsigned int ),
1698        ?>?( unsigned int, unsigned int ), ?>=?( unsigned int, unsigned int );
1699int ?<?( long int, long int ), ?<=?( long int, long int ),
1700        ?>?( long int, long int ), ?>=?( long int, long int );
1701int ?<?( long unsigned int, long unsigned ), ?<=?( long unsigned int, long unsigned ),
1702        ?>?( long unsigned int, long unsigned ), ?>=?( long unsigned int, long unsigned );
1703int ?<?( long long int, long long int ), ?<=?( long long int, long long int ),
1704        ?>?( long long int, long long int ), ?>=?( long long int, long long int );
1705int ?<?( long long unsigned int, long long unsigned ), ?<=?( long long unsigned int, long long unsigned ),
1706        ?>?( long long unsigned int, long long unsigned ), ?>=?( long long unsigned int, long long unsigned );
1707int ?<?( float, float ), ?<=?( float, float ),
1708        ?>?( float, float ), ?>=?( float, float );
1709int ?<?( double, double ), ?<=?( double, double ),
1710        ?>?( double, double ), ?>=?( double, double );
1711int ?<?( long double, long double ), ?<=?( long double, long double ),
1712        ?>?( long double, long double ), ?>=?( long double, long double );
1713forall( dtype DT ) int ?<?( const restrict volatile DT *, const restrict volatile DT * ),
1714        ?<?( _Atomic const restrict volatile DT *, _Atomic const restrict volatile DT * ),
1715        ?<=?( const restrict volatile DT *, const restrict volatile DT * ),
1716        ?<=?( _Atomic const restrict volatile DT *, _Atomic const restrict volatile DT * ),
1717        ?>?( const restrict volatile DT *, const restrict volatile DT * ),
1718        ?>?( _Atomic const restrict volatile DT *, _Atomic const restrict volatile DT * ),
1719        ?>=?( const restrict volatile DT *, const restrict volatile DT * ),
1720        ?>=?( _Atomic const restrict volatile DT *, _Atomic const restrict volatile DT * );
1721\end{lstlisting}
1722For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int© there exist
1723% Don't use predefined: keep this out of prelude.cf.
1724\begin{lstlisting}
1725int ?<?( X, X ),
1726        ?<=?( X, X ),
1727        ?<?( X, X ),
1728        ?>=?( X, X );
1729\end{lstlisting}
1730
1731\semantics
1732The interpretations of a relational expression are the interpretations of the corresponding function call.
1733
1734
1735\subsection{Equality operators}
1736
1737\begin{syntax}
1738\lhs{equality-expression}
1739\rhs \nonterm{relational-expression}
1740\rhs \nonterm{equality-expression} ©==© \nonterm{relational-expression}
1741\rhs \nonterm{equality-expression} ©!=© \nonterm{relational-expression}
1742\end{syntax}
1743
1744\rewriterules
1745\begin{lstlisting}
1746a == b => ?==?( a, b )§\use{?==?}§
1747a != b => ?!=?( a, b )§\use{?"!=?}§
1748\end{lstlisting}
1749
1750\predefined
1751\begin{lstlisting}
1752int ?==?( int, int ), ?!=?( int, int ),
1753        ?==?( unsigned int, unsigned int ), ?!=?( unsigned int, unsigned int ),
1754        ?==?( long int, long int ), ?!=?( long int, long int ),
1755        ?==?( long unsigned int, long unsigned int ), ?!=?( long unsigned int, long unsigned int ),
1756        ?==?( long long int, long long int ), ?!=?( long long int, long long int ),
1757        ?==?( long long unsigned int, long long unsigned int ), ?!=?( long long unsigned int, long long unsigned int ),
1758        ?==?( float, float ), ?!=?( float, float ),
1759        ?==?( _Complex float, float ), ?!=?( _Complex float, float ),
1760        ?==?( float, _Complex float ), ?!=?( float, _Complex float ),
1761        ?==?( _Complex float, _Complex float ), ?!=?( _Complex float, _Complex float ),
1762        ?==?( double, double ), ?!=?( double, double ),
1763        ?==?( _Complex double, double ), ?!=?( _Complex double, double ),
1764        ?==?( double, _Complex double ), ?!=?( double, _Complex double ),
1765        ?==?( _Complex double, _Complex double ), ?!=?( _Complex double, _Complex double ),
1766        ?==?( long double, long double ), ?!=?( long double, long double ),
1767        ?==?( _Complex long double, long double ), ?!=?( _Complex long double, long double ),
1768        ?==?( long double, _Complex long double ), ?!=?( long double, _Complex long double ),
1769        ?==?( _Complex long double, _Complex long double ), ?!=?( _Complex long double, _Complex long double );
1770forall( dtype DT ) int
1771        ?==?( const restrict volatile DT *, const restrict volatile DT * ),
1772        ?!=?( const restrict volatile DT *, const restrict volatile DT * ),
1773        ?==?( const restrict volatile DT *, const restrict volatile void * ),
1774        ?!=?( const restrict volatile DT *, const restrict volatile void * ),
1775        ?==?( const restrict volatile void *, const restrict volatile DT * ),
1776        ?!=?( const restrict volatile void *, const restrict volatile DT * ),
1777        ?==?( const restrict volatile DT *, forall( dtype DT2) const DT2 * ),
1778        ?!=?( const restrict volatile DT *, forall( dtype DT2) const DT2 * ),
1779        ?==?( forall( dtype DT2) const DT2*, const restrict volatile DT * ),
1780        ?!=?( forall( dtype DT2) const DT2*, const restrict volatile DT * ),
1781        ?==?( forall( dtype DT2) const DT2*, forall( dtype DT3) const DT3 * ),
1782        ?!=?( forall( dtype DT2) const DT2*, forall( dtype DT3) const DT3 * ),
1783
1784        ?==?( _Atomic const restrict volatile DT *, _Atomic const restrict volatile DT * ),
1785        ?!=?( _Atomic const restrict volatile DT *, _Atomic const restrict volatile DT * ),
1786        ?==?( _Atomic const restrict volatile DT *, const restrict volatile void * ),
1787        ?!=?( _Atomic const restrict volatile DT *, const restrict volatile void * ),
1788        ?==?( const restrict volatile void *, _Atomic const restrict volatile DT * ),
1789        ?!=?( const restrict volatile void *, _Atomic const restrict volatile DT * ),
1790        ?==?( _Atomic const restrict volatile DT *, forall( dtype DT2) const DT2 * ),
1791        ?!=?( _Atomic const restrict volatile DT *, forall( dtype DT2) const DT2 * ),
1792        ?==?( forall( dtype DT2) const DT2*, _Atomic const restrict volatile DT * ),
1793        ?!=?( forall( dtype DT2) const DT2*, _Atomic const restrict volatile DT * );
1794forall( ftype FT ) int
1795        ?==?( FT *, FT * ), ?!=?( FT *, FT * ),
1796        ?==?( FT *, forall( ftype FT2) FT2 * ), ?!=?( FT *, forall( ftype FT2) FT2 * ),
1797        ?==?( forall( ftype FT2) FT2*, FT * ), ?!=?( forall( ftype FT2) FT2*, FT * ),
1798        ?==?( forall( ftype FT2) FT2*, forall( ftype FT3) FT3 * ), ?!=?( forall( ftype FT2) FT2*, forall( ftype FT3) FT3 * );
1799\end{lstlisting}
1800For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int© there exist
1801% Don't use predefined: keep this out of prelude.cf.
1802\begin{lstlisting}
1803int ?==?( X, X ),
1804        ?!=?( X, X );
1805\end{lstlisting}
1806
1807\begin{rationale}
1808The polymorphic equality operations come in three styles: comparisons between pointers of compatible types, between pointers to ©void© and pointers to object types or incomplete types, and between the \Index{null pointer} constant and pointers to any type.
1809In the last case, a special constraint rule for null pointer constant operands has been replaced by a consequence of the \CFA type system.
1810\end{rationale}
1811
1812\semantics
1813The interpretations of an equality expression are the interpretations of the corresponding function call.
1814
1815\begin{sloppypar}
1816The result of an equality comparison between two pointers to predefined functions or predefined values is implementation-defined.
1817\end{sloppypar}
1818\begin{rationale}
1819The implementation-defined status of equality comparisons allows implementations to use one library routine to implement many predefined functions.
1820These optimization are particularly important when the predefined functions are polymorphic, as is the case for most pointer operations
1821\end{rationale}
1822
1823
1824\subsection{Bitwise AND operator}
1825
1826\begin{syntax}
1827\lhs{AND-expression}
1828\rhs \nonterm{equality-expression}
1829\rhs \nonterm{AND-expression} ©&© \nonterm{equality-expression}
1830\end{syntax}
1831
1832\rewriterules
1833\begin{lstlisting}
1834a & b => ?&?( a, b )§\use{?&?}§
1835\end{lstlisting}
1836
1837\predefined
1838\begin{lstlisting}
1839int ?&?( int, int );
1840unsigned int ?&?( unsigned int, unsigned int );
1841long int ?&?( long int, long int );
1842long unsigned int ?&?( long unsigned int, long unsigned int );
1843long long int ?&?( long long int, long long int );
1844long long unsigned int ?&?( long long unsigned int, long long unsigned int );
1845\end{lstlisting}
1846For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int© there exist
1847% Don't use predefined: keep this out of prelude.cf.
1848\begin{lstlisting}
1849int ?&?( X, X );
1850\end{lstlisting}
1851
1852\semantics
1853The interpretations of a bitwise AND expression are the interpretations of the corresponding function call.
1854
1855
1856\subsection{Bitwise exclusive OR operator}
1857
1858\begin{syntax}
1859\lhs{exclusive-OR-expression}
1860\rhs \nonterm{AND-expression}
1861\rhs \nonterm{exclusive-OR-expression} ©^© \nonterm{AND-expression}
1862\end{syntax}
1863
1864\rewriterules
1865\begin{lstlisting}
1866a ^ b => ?^?( a, b )§\use{?^?}§
1867\end{lstlisting}
1868
1869\predefined
1870\begin{lstlisting}
1871int ?^?( int, int );
1872unsigned int ?^?( unsigned int, unsigned int );
1873long int ?^?( long int, long int );
1874long unsigned int ?^?( long unsigned int, long unsigned int );
1875long long int ?^?( long long int, long long int );
1876long long unsigned int ?^?( long long unsigned int, long long unsigned int );
1877\end{lstlisting}
1878For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int© there exist
1879% Don't use predefined: keep this out of prelude.cf.
1880\begin{lstlisting}
1881int ?^?( X, X );
1882\end{lstlisting}
1883
1884\semantics
1885The interpretations of a bitwise exclusive OR expression are the interpretations of the corresponding function call.
1886
1887
1888\subsection{Bitwise inclusive OR operator}
1889
1890\begin{syntax}
1891\lhs{inclusive-OR-expression}
1892\rhs \nonterm{exclusive-OR-expression}
1893\rhs \nonterm{inclusive-OR-expression} ©|© \nonterm{exclusive-OR-expression}
1894\end{syntax}
1895
1896\rewriterules
1897\begin{lstlisting}
1898a | b => ?|?( a, b )§\use{?"|?}§
1899\end{lstlisting}
1900
1901\predefined
1902\begin{lstlisting}
1903int ?|?( int, int );
1904unsigned int ?|?( unsigned int, unsigned int );
1905long int ?|?( long int, long int );
1906long unsigned int ?|?( long unsigned int, long unsigned int );
1907long long int ?|?( long long int, long long int );
1908long long unsigned int ?|?( long long unsigned int, long long unsigned int );
1909\end{lstlisting}
1910For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int© there exist
1911% Don't use predefined: keep this out of prelude.cf.
1912\begin{lstlisting}
1913int ?|?( X, X );
1914\end{lstlisting}
1915
1916\semantics 
1917The interpretations of a bitwise inclusive OR expression are the interpretations of the corresponding function call.
1918
1919
1920\subsection{Logical AND operator}
1921
1922\begin{syntax}
1923\lhs{logical-AND-expression}
1924\rhs \nonterm{inclusive-OR-expression}
1925\rhs \nonterm{logical-AND-expression} ©&&© \nonterm{inclusive-OR-expression}
1926\end{syntax}
1927
1928\semantics The operands of the expression ``©a && b©'' are treated as ``©(int)((a)!=0)©'' and ``©(int)((b)!=0)©'', which shall both be unambiguous.
1929The expression has only one interpretation, which is of type ©int©.
1930\begin{rationale}
1931When the operands of a logical expression are values of built-in types, and ``©!=©'' has not been redefined for those types, the compiler can optimize away the function calls.
1932
1933A common C idiom omits comparisons to ©0© in the controlling expressions of loops and ©if© statements.
1934For instance, the loop below iterates as long as ©rp© points at a ©Rational© value that is non-zero.
1935
1936\begin{lstlisting}
1937extern otype Rational;§\use{Rational}§
1938extern const Rational 0;§\use{0}§
1939extern int ?!=?( Rational, Rational );
1940Rational *rp;
1941while ( rp && *rp ) { ... }
1942\end{lstlisting}
1943The logical expression calls the ©Rational© inequality operator, passing it ©*rp© and the ©Rational 0©, and getting a 1 or 0 as a result.
1944In contrast, \CC would apply a programmer-defined ©Rational©-to-©int© conversion to ©*rp© in the equivalent situation.
1945The conversion to ©int© would produce a general integer value, which is unfortunate, and possibly dangerous if the conversion was not written with this situation in mind.
1946\end{rationale}
1947
1948
1949\subsection{Logical OR operator}
1950
1951\begin{syntax}
1952\lhs{logical-OR-expression}
1953\rhs \nonterm{logical-AND-expression}
1954\rhs \nonterm{logical-OR-expression} ©||© \nonterm{logical-AND-expression}
1955\end{syntax}
1956
1957\semantics
1958
1959The operands of the expression ``©a || b©'' are treated as ``©(int)((a)!=0)©'' and ``©(int)((b))!=0)©'', which shall both be unambiguous.
1960The expression has only one interpretation, which is of type ©int©.
1961
1962
1963\subsection{Conditional operator}
1964
1965\begin{syntax}
1966\lhs{conditional-expression}
1967\rhs \nonterm{logical-OR-expression}
1968\rhs \nonterm{logical-OR-expression} ©?© \nonterm{expression}
1969         ©:© \nonterm{conditional-expression}
1970\end{syntax}
1971
1972\semantics
1973In the conditional expression\use{?:} ``©a?b:c©'', if the second and third operands both have an interpretation with ©void© type, then the expression has an interpretation with type ©void©, equivalent to
1974\begin{lstlisting}
1975( int)(( a)!=0) ? ( void)( b) : ( void)( c)
1976\end{lstlisting}
1977
1978If the second and third operands both have interpretations with non-©void© types, the expression is treated as if it were the call ``©cond((a)!=0, b, c)©'', with ©cond© declared as
1979\begin{lstlisting}
1980forall( otype T ) T cond( int, T, T );
1981forall( dtype D ) void * cond( int, D *, void * ), * cond( int, void *, D * );
1982forall( dtype D ) _atomic void * cond(
1983        int, _Atomic D *, _Atomic void * ), * cond( int, _Atomic void *, _Atomic D * );
1984forall( dtype D ) const void * cond(
1985        int, const D *, const void * ), * cond( int, const void *, const D * );
1986forall( dtype D ) restrict void * cond(
1987        int, restrict D *, restrict void * ), * cond( int, restrict void *, restrict D * );
1988forall( dtype D ) volatile void * cond(
1989        int, volatile D *, volatile void * ), * cond( int, volatile void *, volatile D * );
1990forall( dtype D ) _Atomic const void * cond(
1991        int, _Atomic const D *, _Atomic const void * ), * cond( int, _Atomic const void *, _Atomic const D * );
1992forall( dtype D ) _Atomic restrict void * cond(
1993        int, _Atomic restrict D *, _Atomic restrict void * ), * cond( int, _Atomic restrict void *, _Atomic restrict D * );
1994forall( dtype D ) _Atomic volatile void * cond(
1995        int, _Atomic volatile D *, _Atomic volatile void * ), * cond( int, _Atomic volatile void *, _Atomic volatile D * );
1996forall( dtype D ) const restrict void * cond(
1997        int, const restrict D *, const restrict void * ), * cond( int, const restrict void *, const restrict D * );
1998forall( dtype D ) const volatile void * cond(
1999        int, const volatile D *, const volatile void * ), * cond( int, const volatile void *, const volatile D * );
2000forall( dtype D ) restrict volatile void * cond(
2001        int, restrict volatile D *, restrict volatile void * ), * cond( int, restrict volatile void *, restrict volatile D * );
2002forall( dtype D ) _Atomic const restrict void * cond(
2003        int, _Atomic const restrict D *, _Atomic const restrict void * ),
2004        * cond( int, _Atomic const restrict void *, _Atomic const restrict D * );
2005forall( dtype D ) _Atomic const volatile void * cond(
2006        int, _Atomic const volatile D *, _Atomic const volatile void * ),
2007        * cond( int, _Atomic const volatile void *, _Atomic const volatile D * );
2008forall( dtype D ) _Atomic restrict volatile void * cond(
2009        int, _Atomic restrict volatile D *, _Atomic restrict volatile void * ),
2010        * cond( int, _Atomic restrict volatile void *, _Atomic restrict volatile D * );
2011forall( dtype D ) const restrict volatile void * cond(
2012        int, const restrict volatile D *, const restrict volatile void * ),
2013        * cond( int, const restrict volatile void *, const restrict volatile D * );
2014forall( dtype D ) _Atomic const restrict volatile void * cond(
2015        int, _Atomic const restrict volatile D *, _Atomic const restrict volatile void * ),
2016        * cond( int, _Atomic const restrict volatile void *, _Atomic const restrict volatile D * );
2017\end{lstlisting}
2018
2019\begin{rationale}
2020The object of the above is to apply the \Index{usual arithmetic conversion}s when the second and third operands have arithmetic type, and to combine the qualifiers of the second and third operands if they are pointers.
2021\end{rationale}
2022
2023\examples
2024\begin{lstlisting}
2025#include <stdlib.h>
2026int i;
2027long l;
2028rand() ? i : l;
2029\end{lstlisting}
2030The best interpretation infers the expression's type to be ©long© and applies the safe ©int©-to-©long© conversion to ©i©.
2031
2032\begin{lstlisting}
2033const int *cip;
2034volatile int *vip;
2035rand() ? cip : vip;
2036\end{lstlisting}
2037The expression has type ©const volatile int *©, with safe conversions applied to the second and third operands to add ©volatile© and ©const© qualifiers, respectively.
2038
2039\begin{lstlisting}
2040rand() ? cip : 0;
2041\end{lstlisting}
2042The expression has type ©const int *©, with a specialization conversion applied to ©0©.
2043
2044
2045\subsection{Assignment operators}
2046
2047\begin{syntax}
2048\lhs{assignment-expression}
2049\rhs \nonterm{conditional-expression}
2050\rhs \nonterm{unary-expression} \nonterm{assignment-operator}
2051         \nonterm{assignment-expression}
2052\lhs{assignment-operator} one of
2053\rhs ©=©\ \ ©*=©\ \ ©/=©\ \ ©%=©\ \ ©+=©\ \ ©-=©\ \ ©<<=©\ \ ©>>=©\ \ ©&=©\ \ ©^=©\ \ ©|=©
2054\end{syntax}
2055
2056\rewriterules
2057Let ``©<-©'' be any of the assignment operators.
2058Then
2059\use{?=?}\use{?*=?}\use{?/=?}\use{?%=?}\use{?+=?}\use{?-=?}\use{?>>=?}\use{?&=?}\use{?^=?}\use{?"|=?}%use{?<<=?}
2060\begin{lstlisting}
2061a <- b => ?<-?( &( a ), b )
2062\end{lstlisting}
2063
2064\semantics
2065Each interpretation of the left operand of an assignment expression is considered separately.
2066For each interpretation that is a bit-field or is declared with the ©register© storage class specifier, the expression has one valid interpretation, with the type of the left operand.
2067The right operand is cast to that type, and the assignment expression is ambiguous if either operand is.
2068For the remaining interpretations, the expression is rewritten, and the interpretations of the assignment expression are the interpretations of the corresponding function call.
2069Finally, all interpretations of the expression produced for the different interpretations of the left operand are combined to produce the interpretations of the expression as a whole;
2070where interpretations have compatible result types, the best interpretations are selected in the manner described for function call expressions.
2071
2072
2073\subsubsection{Simple assignment}
2074
2075\predefined
2076\begin{lstlisting}
2077_Bool
2078        ?=?( volatile _Bool *, _Bool ),
2079        ?=?( volatile _Bool *, forall( dtype D ) D * ),
2080        ?=?( volatile _Bool *, forall( ftype F ) F * ),
2081        ?=?( _Atomic volatile _Bool *, _Bool ),
2082        ?=?( _Atomic volatile _Bool *, forall( dtype D ) D * ),
2083        ?=?( _Atomic volatile _Bool *, forall( ftype F ) F * );
2084char
2085        ?=?( volatile char *, char ),
2086        ?=?( _Atomic volatile char *, char );
2087unsigned char
2088        ?=?( volatile unsigned char *, unsigned char ),
2089        ?=?( _Atomic volatile unsigned char *, unsigned char );
2090signed char
2091        ?=?( volatile signed char *, signed char ),
2092        ?=?( _Atomic volatile signed char *, signed char );
2093short int
2094        ?=?( volatile short int *, short int ),
2095        ?=?( _Atomic volatile short int *, short int );
2096unsigned short
2097        ?=?( volatile unsigned int *, unsigned int ),
2098        ?=?( _Atomic volatile unsigned int *, unsigned int );
2099int
2100        ?=?( volatile int *, int ),
2101        ?=?( _Atomic volatile int *, int );
2102unsigned int
2103        ?=?( volatile unsigned int *, unsigned int ),
2104        ?=?( _Atomic volatile unsigned int *, unsigned int );
2105long int
2106        ?=?( volatile long int *, long int ),
2107        ?=?( _Atomic volatile long int *, long int );
2108unsigned long int
2109        ?=?( volatile unsigned long int *, unsigned long int ),
2110        ?=?( _Atomic volatile unsigned long int *, unsigned long int );
2111long long int
2112        ?=?( volatile long long int *, long long int ),
2113        ?=?( _Atomic volatile long long int *, long long int );
2114unsigned long long int
2115        ?=?( volatile unsigned long long int *, unsigned long long int ),
2116        ?=?( _Atomic volatile unsigned long long int *, unsigned long long int );
2117float
2118        ?=?( volatile float *, float ),
2119        ?=?( _Atomic volatile float *, float );
2120double
2121        ?=?( volatile double *, double ),
2122        ?=?( _Atomic volatile double *, double );
2123long double
2124        ?=?( volatile long double *, long double ),
2125        ?=?( _Atomic volatile long double *, long double );
2126_Complex float
2127        ?=?( volatile float *, float ),
2128        ?=?( _Atomic volatile float *, float );
2129_Complex double
2130        ?=?( volatile double *, double ),
2131        ?=?( _Atomic volatile double *, double );
2132_Complex long double
2133        ?=?( volatile _Complex long double *, _Complex long double ),
2134        ?=?( _Atomic volatile _Complex long double *, _Atomic _Complex long double );
2135forall( ftype FT ) FT
2136        * ?=?( FT * volatile *, FT * ),
2137        * ?=?( FT * volatile *, forall( ftype F ) F * );
2138forall( ftype FT ) FT const
2139        * ?=?( FT const * volatile *, FT const * ),
2140        * ?=?( FT const * volatile *, forall( ftype F ) F * );
2141forall( ftype FT ) FT volatile
2142        * ?=?( FT volatile * volatile *, FT * ),
2143        * ?=?( FT volatile * volatile *, forall( ftype F ) F * );
2144forall( ftype FT ) FT const
2145        * ?=?( FT const volatile * volatile *, FT const * ),
2146        * ?=?( FT const volatile * volatile *, forall( ftype F ) F * );
2147forall( dtype DT ) DT
2148        * ?=?( DT * restrict volatile *, DT * ),
2149        * ?=?( DT * restrict volatile *, void * ),
2150        * ?=?( DT * restrict volatile *, forall( dtype D ) D * ),
2151        * ?=?( DT * _Atomic restrict volatile *, DT * ),
2152        * ?=?( DT * _Atomic restrict volatile *, void * ),
2153        * ?=?( DT * _Atomic restrict volatile *, forall( dtype D ) D * );
2154forall( dtype DT ) DT _Atomic
2155        * ?=?( _Atomic DT * restrict volatile *, DT _Atomic * ),
2156        * ?=?( _Atomic DT * restrict volatile *, void * ),
2157        * ?=?( _Atomic DT * restrict volatile *, forall( dtype D ) D * ),
2158        * ?=?( _Atomic DT * _Atomic restrict volatile *, DT _Atomic * ),
2159        * ?=?( _Atomic DT * _Atomic restrict volatile *, void * ),
2160        * ?=?( _Atomic DT * _Atomic restrict volatile *, forall( dtype D ) D * );
2161forall( dtype DT ) DT const
2162        * ?=?( DT const * restrict volatile *, DT const * ),
2163        * ?=?( DT const * restrict volatile *, void const * ),
2164        * ?=?( DT const * restrict volatile *, forall( dtype D ) D * ),
2165        * ?=?( DT const * _Atomic restrict volatile *, DT const * ),
2166        * ?=?( DT const * _Atomic restrict volatile *, void const * ),
2167        * ?=?( DT const * _Atomic restrict volatile *, forall( dtype D ) D * );
2168forall( dtype DT ) DT restrict
2169        * ?=?( restrict DT * restrict volatile *, DT restrict * ),
2170        * ?=?( restrict DT * restrict volatile *, void * ),
2171        * ?=?( restrict DT * restrict volatile *, forall( dtype D ) D * ),
2172        * ?=?( restrict DT * _Atomic restrict volatile *, DT restrict * ),
2173        * ?=?( restrict DT * _Atomic restrict volatile *, void * ),
2174        * ?=?( restrict DT * _Atomic restrict volatile *, forall( dtype D ) D * );
2175forall( dtype DT ) DT volatile
2176        * ?=?( DT volatile * restrict volatile *, DT volatile * ),
2177        * ?=?( DT volatile * restrict volatile *, void volatile * ),
2178        * ?=?( DT volatile * restrict volatile *, forall( dtype D ) D * ),
2179        * ?=?( DT volatile * _Atomic restrict volatile *, DT volatile * ),
2180        * ?=?( DT volatile * _Atomic restrict volatile *, void volatile * ),
2181        * ?=?( DT volatile * _Atomic restrict volatile *, forall( dtype D ) D * );
2182forall( dtype DT ) DT _Atomic const
2183        * ?=?( DT _Atomic const * restrict volatile *, DT _Atomic const * ),
2184        * ?=?( DT _Atomic const * restrict volatile *, void const * ),
2185        * ?=?( DT _Atomic const * restrict volatile *, forall( dtype D ) D * ),
2186        * ?=?( DT _Atomic const * _Atomic restrict volatile *, DT _Atomic const * ),
2187        * ?=?( DT _Atomic const * _Atomic restrict volatile *, void const * ),
2188        * ?=?( DT _Atomic const * _Atomic restrict volatile *, forall( dtype D ) D * );
2189forall( dtype DT ) DT _Atomic restrict
2190        * ?=?( _Atomic restrict DT * restrict volatile *, DT _Atomic restrict * ),
2191        * ?=?( _Atomic restrict DT * restrict volatile *, void * ),
2192        * ?=?( _Atomic restrict DT * restrict volatile *, forall( dtype D ) D * ),
2193        * ?=?( _Atomic restrict DT * _Atomic restrict volatile *, DT _Atomic restrict * ),
2194        * ?=?( _Atomic restrict DT * _Atomic restrict volatile *, void * ),
2195        * ?=?( _Atomic restrict DT * _Atomic restrict volatile *, forall( dtype D ) D * );
2196forall( dtype DT ) DT _Atomic volatile
2197        * ?=?( DT _Atomic volatile * restrict volatile *, DT _Atomic volatile * ),
2198        * ?=?( DT _Atomic volatile * restrict volatile *, void volatile * ),
2199        * ?=?( DT _Atomic volatile * restrict volatile *, forall( dtype D ) D * ),
2200        * ?=?( DT _Atomic volatile * _Atomic restrict volatile *, DT _Atomic volatile * ),
2201        * ?=?( DT _Atomic volatile * _Atomic restrict volatile *, void volatile * ),
2202        * ?=?( DT _Atomic volatile * _Atomic restrict volatile *, forall( dtype D ) D * );
2203forall( dtype DT ) DT const restrict
2204        * ?=?( DT const restrict * restrict volatile *, DT const restrict * ),
2205        * ?=?( DT const restrict * restrict volatile *, void const * ),
2206        * ?=?( DT const restrict * restrict volatile *, forall( dtype D ) D * ),
2207        * ?=?( DT const restrict * _Atomic restrict volatile *, DT const restrict * ),
2208        * ?=?( DT const restrict * _Atomic restrict volatile *, void const * ),
2209        * ?=?( DT const restrict * _Atomic restrict volatile *, forall( dtype D ) D * );
2210forall( dtype DT ) DT const volatile
2211        * ?=?( DT const volatile * restrict volatile *, DT const volatile * ),
2212        * ?=?( DT const volatile * restrict volatile *, void const volatile * ),
2213        * ?=?( DT const volatile * restrict volatile *, forall( dtype D ) D * ),
2214        * ?=?( DT const volatile * _Atomic restrict volatile *, DT const volatile * ),
2215        * ?=?( DT const volatile * _Atomic restrict volatile *, void const volatile * ),
2216        * ?=?( DT const volatile * _Atomic restrict volatile *, forall( dtype D ) D * );
2217forall( dtype DT ) DT restrict volatile
2218        * ?=?( DT restrict volatile * restrict volatile *, DT restrict volatile * ),
2219        * ?=?( DT restrict volatile * restrict volatile *, void volatile * ),
2220        * ?=?( DT restrict volatile * restrict volatile *, forall( dtype D ) D * ),
2221        * ?=?( DT restrict volatile * _Atomic restrict volatile *, DT restrict volatile * ),
2222        * ?=?( DT restrict volatile * _Atomic restrict volatile *, void volatile * ),
2223        * ?=?( DT restrict volatile * _Atomic restrict volatile *, forall( dtype D ) D * );
2224forall( dtype DT ) DT _Atomic const restrict
2225        * ?=?( DT _Atomic const restrict * restrict volatile *,
2226         DT _Atomic const restrict * ),
2227        * ?=?( DT _Atomic const restrict * restrict volatile *,
2228         void const * ),
2229        * ?=?( DT _Atomic const restrict * restrict volatile *,
2230         forall( dtype D ) D * ),
2231        * ?=?( DT _Atomic const restrict * _Atomic restrict volatile *,
2232         DT _Atomic const restrict * ),
2233        * ?=?( DT _Atomic const restrict * _Atomic restrict volatile *,
2234         void const * ),
2235        * ?=?( DT _Atomic const restrict * _Atomic restrict volatile *,
2236         forall( dtype D ) D * );
2237forall( dtype DT ) DT _Atomic const volatile
2238        * ?=?( DT _Atomic const volatile * restrict volatile *,
2239         DT _Atomic const volatile * ),
2240        * ?=?( DT _Atomic const volatile * restrict volatile *,
2241         void const volatile * ),
2242        * ?=?( DT _Atomic const volatile * restrict volatile *,
2243         forall( dtype D ) D * ),
2244        * ?=?( DT _Atomic const volatile * _Atomic restrict volatile *,
2245         DT _Atomic const volatile * ),
2246        * ?=?( DT _Atomic const volatile * _Atomic restrict volatile *,
2247         void const volatile * ),
2248        * ?=?( DT _Atomic const volatile * _Atomic restrict volatile *,
2249         forall( dtype D ) D * );
2250forall( dtype DT ) DT _Atomic restrict volatile
2251        * ?=?( DT _Atomic restrict volatile * restrict volatile *,
2252         DT _Atomic restrict volatile * ),
2253        * ?=?( DT _Atomic restrict volatile * restrict volatile *,
2254         void volatile * ),
2255        * ?=?( DT _Atomic restrict volatile * restrict volatile *,
2256         forall( dtype D ) D * ),
2257        * ?=?( DT _Atomic restrict volatile * _Atomic restrict volatile *,
2258         DT _Atomic restrict volatile * ),
2259        * ?=?( DT _Atomic restrict volatile * _Atomic restrict volatile *,
2260         void volatile * ),
2261        * ?=?( DT _Atomic restrict volatile * _Atomic restrict volatile *,
2262         forall( dtype D ) D * );
2263forall( dtype DT ) DT const restrict volatile
2264        * ?=?( DT const restrict volatile * restrict volatile *,
2265         DT const restrict volatile * ),
2266        * ?=?( DT const restrict volatile * restrict volatile *,
2267         void const volatile * ),
2268        * ?=?( DT const restrict volatile * restrict volatile *,
2269         forall( dtype D ) D * ),
2270        * ?=?( DT const restrict volatile * _Atomic restrict volatile *,
2271         DT const restrict volatile * ),
2272        * ?=?( DT const restrict volatile * _Atomic restrict volatile *,
2273         void const volatile * ),
2274        * ?=?( DT const restrict volatile * _Atomic restrict volatile *,
2275         forall( dtype D ) D * );
2276forall( dtype DT ) DT _Atomic const restrict volatile
2277        * ?=?( DT _Atomic const restrict volatile * restrict volatile *,
2278         DT _Atomic const restrict volatile * ),
2279        * ?=?( DT _Atomic const restrict volatile * restrict volatile *,
2280         void const volatile * ),
2281        * ?=?( DT _Atomic const restrict volatile * restrict volatile *,
2282         forall( dtype D ) D * ),
2283        * ?=?( DT _Atomic const restrict volatile * _Atomic restrict volatile *,
2284         DT _Atomic const restrict volatile * ),
2285        * ?=?( DT _Atomic const restrict volatile * _Atomic restrict volatile *,
2286         void const volatile * ),
2287        * ?=?( DT _Atomic const restrict volatile * _Atomic restrict volatile *,
2288         forall( dtype D ) D * );
2289forall( dtype DT ) void
2290        * ?=?( void * restrict volatile *, DT * );
2291forall( dtype DT ) void const
2292        * ?=?( void const * restrict volatile *, DT const * );
2293forall( dtype DT ) void volatile
2294        * ?=?( void volatile * restrict volatile *, DT volatile * );
2295forall( dtype DT ) void const volatile
2296        * ?=?( void const volatile * restrict volatile *, DT const volatile * );
2297\end{lstlisting}
2298\begin{rationale}
2299The pattern of overloadings for simple assignment resembles that of pointer increment and decrement, except that the polymorphic pointer assignment functions declare a ©dtype© parameter, instead of a ©type© parameter, because the left operand may be a pointer to an incomplete type.
2300\end{rationale}
2301
2302For every complete structure or union type ©S© there exist
2303% Don't use predefined: keep this out of prelude.cf.
2304\begin{lstlisting}
2305S ?=?( S volatile *, S ), ?=?( S _Atomic volatile *, S );
2306\end{lstlisting}
2307
2308For every extended integer type ©X© there exist
2309% Don't use predefined: keep this out of prelude.cf.
2310\begin{lstlisting}
2311X ?=?( X volatile *, X ), ?=?( X _Atomic volatile *, X );
2312\end{lstlisting}
2313
2314For every complete enumerated type ©E© there exist
2315% Don't use predefined: keep this out of prelude.cf.
2316\begin{lstlisting}
2317E ?=?( E volatile *, int ), ?=?( E _Atomic volatile *, int );
2318\end{lstlisting}
2319\begin{rationale}
2320The right-hand argument is ©int© because enumeration constants have type ©int©.
2321\end{rationale}
2322
2323\semantics
2324The structure assignment functions provide member-wise assignment;
2325each non-array member and each element of each array member of the right argument is assigned to the corresponding member or element of the left argument using the assignment function defined for its type.
2326All other assignment functions have the same effect as the corresponding C assignment expression.
2327\begin{rationale}
2328Note that, by default, union assignment\index{deficiencies!union assignment} uses C semantics---that is, bitwise copy---even if some of the union members have programmer-defined assignment functions.
2329\end{rationale}
2330
2331
2332\subsubsection{Compound assignment}
2333
2334\predefined
2335\begin{lstlisting}
2336forall( otype T ) T
2337        * ?+=?( T * restrict volatile *, ptrdiff_t ),
2338        * ?-=?( T * restrict volatile *, ptrdiff_t ),
2339        * ?+=?( T * _Atomic restrict volatile *, ptrdiff_t ),
2340        * ?-=?( T * _Atomic restrict volatile *, ptrdiff_t );
2341forall( otype T ) T _Atomic
2342        * ?+=?( T _Atomic * restrict volatile *, ptrdiff_t ),
2343        * ?-=?( T _Atomic * restrict volatile *, ptrdiff_t ),
2344        * ?+=?( T _Atomic * _Atomic restrict volatile *, ptrdiff_t ),
2345        * ?-=?( T _Atomic * _Atomic restrict volatile *, ptrdiff_t );
2346forall( otype T ) T const
2347        * ?+=?( T const * restrict volatile *, ptrdiff_t ),
2348        * ?-=?( T const * restrict volatile *, ptrdiff_t ),
2349        * ?+=?( T const * _Atomic restrict volatile *, ptrdiff_t ),
2350        * ?-=?( T const * _Atomic restrict volatile *, ptrdiff_t );
2351forall( otype T ) T restrict
2352        * ?+=?( T restrict * restrict volatile *, ptrdiff_t ),
2353        * ?-=?( T restrict * restrict volatile *, ptrdiff_t ),
2354        * ?+=?( T restrict * _Atomic restrict volatile *, ptrdiff_t ),
2355        * ?-=?( T restrict * _Atomic restrict volatile *, ptrdiff_t );
2356forall( otype T ) T volatile
2357        * ?+=?( T volatile * restrict volatile *, ptrdiff_t ),
2358        * ?-=?( T volatile * restrict volatile *, ptrdiff_t ),
2359        * ?+=?( T volatile * _Atomic restrict volatile *, ptrdiff_t ),
2360        * ?-=?( T volatile * _Atomic restrict volatile *, ptrdiff_t );
2361forall( otype T ) T _Atomic const
2362        * ?+=?( T _Atomic const restrict volatile *, ptrdiff_t ),
2363        * ?-=?( T _Atomic const restrict volatile *, ptrdiff_t ),
2364        * ?+=?( T _Atomic const _Atomic restrict volatile *, ptrdiff_t ),
2365        * ?-=?( T _Atomic const _Atomic restrict volatile *, ptrdiff_t );
2366forall( otype T ) T _Atomic restrict
2367        * ?+=?( T _Atomic restrict * restrict volatile *, ptrdiff_t ),
2368        * ?-=?( T _Atomic restrict * restrict volatile *, ptrdiff_t ),
2369        * ?+=?( T _Atomic restrict * _Atomic restrict volatile *, ptrdiff_t ),
2370        * ?-=?( T _Atomic restrict * _Atomic restrict volatile *, ptrdiff_t );
2371forall( otype T ) T _Atomic volatile
2372        * ?+=?( T _Atomic volatile * restrict volatile *, ptrdiff_t ),
2373        * ?-=?( T _Atomic volatile * restrict volatile *, ptrdiff_t ),
2374        * ?+=?( T _Atomic volatile * _Atomic restrict volatile *, ptrdiff_t ),
2375        * ?-=?( T _Atomic volatile * _Atomic restrict volatile *, ptrdiff_t );
2376forall( otype T ) T const restrict
2377        * ?+=?( T const restrict * restrict volatile *, ptrdiff_t ),
2378        * ?-=?( T const restrict * restrict volatile *, ptrdiff_t ),
2379        * ?+=?( T const restrict * _Atomic restrict volatile *, ptrdiff_t ),
2380        * ?-=?( T const restrict * _Atomic restrict volatile *, ptrdiff_t );
2381forall( otype T ) T const volatile
2382        * ?+=?( T const volatile * restrict volatile *, ptrdiff_t ),
2383        * ?-=?( T const volatile * restrict volatile *, ptrdiff_t ),
2384        * ?+=?( T const volatile * _Atomic restrict volatile *, ptrdiff_t ),
2385        * ?-=?( T const volatile * _Atomic restrict volatile *, ptrdiff_t );
2386forall( otype T ) T restrict volatile
2387        * ?+=?( T restrict volatile * restrict volatile *, ptrdiff_t ),
2388        * ?-=?( T restrict volatile * restrict volatile *, ptrdiff_t ),
2389        * ?+=?( T restrict volatile * _Atomic restrict volatile *, ptrdiff_t ),
2390        * ?-=?( T restrict volatile * _Atomic restrict volatile *, ptrdiff_t );
2391forall( otype T ) T _Atomic const restrict
2392        * ?+=?( T _Atomic const restrict * restrict volatile *, ptrdiff_t ),
2393        * ?-=?( T _Atomic const restrict * restrict volatile *, ptrdiff_t ),
2394        * ?+=?( T _Atomic const restrict * _Atomic restrict volatile *, ptrdiff_t ),
2395        * ?-=?( T _Atomic const restrict * _Atomic restrict volatile *, ptrdiff_t );
2396forall( otype T ) T _Atomic const volatile
2397        * ?+=?( T _Atomic const volatile * restrict volatile *, ptrdiff_t ),
2398        * ?-=?( T _Atomic const volatile * restrict volatile *, ptrdiff_t ),
2399        * ?+=?( T _Atomic const volatile * _Atomic restrict volatile *, ptrdiff_t ),
2400        * ?-=?( T _Atomic const volatile * _Atomic restrict volatile *, ptrdiff_t );
2401forall( otype T ) T _Atomic restrict volatile
2402        * ?+=?( T _Atomic restrict volatile * restrict volatile *, ptrdiff_t ),
2403        * ?-=?( T _Atomic restrict volatile * restrict volatile *, ptrdiff_t ),
2404        * ?+=?( T _Atomic restrict volatile * _Atomic restrict volatile *, ptrdiff_t ),
2405        * ?-=?( T _Atomic restrict volatile * _Atomic restrict volatile *, ptrdiff_t );
2406forall( otype T ) T const restrict volatile
2407        * ?+=?( T const restrict volatile * restrict volatile *, ptrdiff_t ),
2408        * ?-=?( T const restrict volatile * restrict volatile *, ptrdiff_t ),
2409        * ?+=?( T const restrict volatile * _Atomic restrict volatile *, ptrdiff_t ),
2410        * ?-=?( T const restrict volatile * _Atomic restrict volatile *, ptrdiff_t );
2411forall( otype T ) T _Atomic const restrict volatile
2412        * ?+=?( T _Atomic const restrict volatile * restrict volatile *, ptrdiff_t ),
2413        * ?-=?( T _Atomic const restrict volatile * restrict volatile *, ptrdiff_t ),
2414        * ?+=?( T _Atomic const restrict volatile * _Atomic restrict volatile *, ptrdiff_t ),
2415        * ?-=?( T _Atomic const restrict volatile * _Atomic restrict volatile *, ptrdiff_t );
2416
2417_Bool
2418        ?*=?( _Bool volatile *, _Bool ),
2419        ?/=?( _Bool volatile *, _Bool ),
2420        ?+=?( _Bool volatile *, _Bool ),
2421        ?-=?( _Bool volatile *, _Bool ),
2422        ?%=?( _Bool volatile *, _Bool ),
2423        ?<<=?( _Bool volatile *, int ),
2424        ?>>=?( _Bool volatile *, int ),
2425        ?&=?( _Bool volatile *, _Bool ),
2426        ?^=?( _Bool volatile *, _Bool ),
2427        ?|=?( _Bool volatile *, _Bool );
2428char
2429        ?*=?( char volatile *, char ),
2430        ?/=?( char volatile *, char ),
2431        ?+=?( char volatile *, char ),
2432        ?-=?( char volatile *, char ),
2433        ?%=?( char volatile *, char ),
2434        ?<<=?( char volatile *, int ),
2435        ?>>=?( char volatile *, int ),
2436        ?&=?( char volatile *, char ),
2437        ?^=?( char volatile *, char ),
2438        ?|=?( char volatile *, char );
2439unsigned char
2440        ?*=?( unsigned char volatile *, unsigned char ),
2441        ?/=?( unsigned char volatile *, unsigned char ),
2442        ?+=?( unsigned char volatile *, unsigned char ),
2443        ?-=?( unsigned char volatile *, unsigned char ),
2444        ?%=?( unsigned char volatile *, unsigned char ),
2445        ?<<=?( unsigned char volatile *, int ),
2446        ?>>=?( unsigned char volatile *, int ),
2447        ?&=?( unsigned char volatile *, unsigned char ),
2448        ?^=?( unsigned char volatile *, unsigned char ),
2449        ?|=?( unsigned char volatile *, unsigned char );
2450signed char
2451        ?*=?( signed char volatile *, signed char ),
2452        ?/=?( signed char volatile *, signed char ),
2453        ?+=?( signed char volatile *, signed char ),
2454        ?-=?( signed char volatile *, signed char ),
2455        ?%=?( signed char volatile *, signed char ),
2456        ?<<=?( signed char volatile *, int ),
2457        ?>>=?( signed char volatile *, int ),
2458        ?&=?( signed char volatile *, signed char ),
2459        ?^=?( signed char volatile *, signed char ),
2460        ?|=?( signed char volatile *, signed char );
2461short int
2462        ?*=?( short int volatile *, short int ),
2463        ?/=?( short int volatile *, short int ),
2464        ?+=?( short int volatile *, short int ),
2465        ?-=?( short int volatile *, short int ),
2466        ?%=?( short int volatile *, short int ),
2467        ?<<=?( short int volatile *, int ),
2468        ?>>=?( short int volatile *, int ),
2469        ?&=?( short int volatile *, short int ),
2470        ?^=?( short int volatile *, short int ),
2471        ?|=?( short int volatile *, short int );
2472unsigned short int
2473        ?*=?( unsigned short int volatile *, unsigned short int ),
2474        ?/=?( unsigned short int volatile *, unsigned short int ),
2475        ?+=?( unsigned short int volatile *, unsigned short int ),
2476        ?-=?( unsigned short int volatile *, unsigned short int ),
2477        ?%=?( unsigned short int volatile *, unsigned short int ),
2478        ?<<=?( unsigned short int volatile *, int ),
2479        ?>>=?( unsigned short int volatile *, int ),
2480        ?&=?( unsigned short int volatile *, unsigned short int ),
2481        ?^=?( unsigned short int volatile *, unsigned short int ),
2482        ?|=?( unsigned short int volatile *, unsigned short int );
2483int
2484        ?*=?( int volatile *, int ),
2485        ?/=?( int volatile *, int ),
2486        ?+=?( int volatile *, int ),
2487        ?-=?( int volatile *, int ),
2488        ?%=?( int volatile *, int ),
2489        ?<<=?( int volatile *, int ),
2490        ?>>=?( int volatile *, int ),
2491        ?&=?( int volatile *, int ),
2492        ?^=?( int volatile *, int ),
2493        ?|=?( int volatile *, int );
2494unsigned int
2495        ?*=?( unsigned int volatile *, unsigned int ),
2496        ?/=?( unsigned int volatile *, unsigned int ),
2497        ?+=?( unsigned int volatile *, unsigned int ),
2498        ?-=?( unsigned int volatile *, unsigned int ),
2499        ?%=?( unsigned int volatile *, unsigned int ),
2500        ?<<=?( unsigned int volatile *, int ),
2501        ?>>=?( unsigned int volatile *, int ),
2502        ?&=?( unsigned int volatile *, unsigned int ),
2503        ?^=?( unsigned int volatile *, unsigned int ),
2504        ?|=?( unsigned int volatile *, unsigned int );
2505long int
2506        ?*=?( long int volatile *, long int ),
2507        ?/=?( long int volatile *, long int ),
2508        ?+=?( long int volatile *, long int ),
2509        ?-=?( long int volatile *, long int ),
2510        ?%=?( long int volatile *, long int ),
2511        ?<<=?( long int volatile *, int ),
2512        ?>>=?( long int volatile *, int ),
2513        ?&=?( long int volatile *, long int ),
2514        ?^=?( long int volatile *, long int ),
2515        ?|=?( long int volatile *, long int );
2516unsigned long int
2517        ?*=?( unsigned long int volatile *, unsigned long int ),
2518        ?/=?( unsigned long int volatile *, unsigned long int ),
2519        ?+=?( unsigned long int volatile *, unsigned long int ),
2520        ?-=?( unsigned long int volatile *, unsigned long int ),
2521        ?%=?( unsigned long int volatile *, unsigned long int ),
2522        ?<<=?( unsigned long int volatile *, int ),
2523        ?>>=?( unsigned long int volatile *, int ),
2524        ?&=?( unsigned long int volatile *, unsigned long int ),
2525        ?^=?( unsigned long int volatile *, unsigned long int ),
2526        ?|=?( unsigned long int volatile *, unsigned long int );
2527long long int
2528        ?*=?( long long int volatile *, long long int ),
2529        ?/=?( long long int volatile *, long long int ),
2530        ?+=?( long long int volatile *, long long int ),
2531        ?-=?( long long int volatile *, long long int ),
2532        ?%=?( long long int volatile *, long long int ),
2533        ?<<=?( long long int volatile *, int ),
2534        ?>>=?( long long int volatile *, int ),
2535        ?&=?( long long int volatile *, long long int ),
2536        ?^=?( long long int volatile *, long long int ),
2537        ?|=?( long long int volatile *, long long int );
2538unsigned long long int
2539        ?*=?( unsigned long long int volatile *, unsigned long long int ),
2540        ?/=?( unsigned long long int volatile *, unsigned long long int ),
2541        ?+=?( unsigned long long int volatile *, unsigned long long int ),
2542        ?-=?( unsigned long long int volatile *, unsigned long long int ),
2543        ?%=?( unsigned long long int volatile *, unsigned long long int ),
2544        ?<<=?( unsigned long long int volatile *, int ),
2545        ?>>=?( unsigned long long int volatile *, int ),
2546        ?&=?( unsigned long long int volatile *, unsigned long long int ),
2547        ?^=?( unsigned long long int volatile *, unsigned long long int ),
2548        ?|=?( unsigned long long int volatile *, unsigned long long int );
2549float
2550        ?*=?( float volatile *, float ),
2551        ?/=?( float volatile *, float ),
2552        ?+=?( float volatile *, float ),
2553        ?-=?( float volatile *, float );
2554double
2555        ?*=?( double volatile *, double ),
2556        ?/=?( double volatile *, double ),
2557        ?+=?( double volatile *, double ),
2558        ?-=?( double volatile *, double );
2559long double
2560        ?*=?( long double volatile *, long double ),
2561        ?/=?( long double volatile *, long double ),
2562        ?+=?( long double volatile *, long double ),
2563        ?-=?( long double volatile *, long double );
2564_Complex float
2565        ?*=?( _Complex float volatile *, _Complex float ),
2566        ?/=?( _Complex float volatile *, _Complex float ),
2567        ?+=?( _Complex float volatile *, _Complex float ),
2568        ?-=?( _Complex float volatile *, _Complex float );
2569_Complex double
2570        ?*=?( _Complex double volatile *, _Complex double ),
2571        ?/=?( _Complex double volatile *, _Complex double ),
2572        ?+=?( _Complex double volatile *, _Complex double ),
2573        ?-=?( _Complex double volatile *, _Complex double );
2574_Complex long double
2575        ?*=?( _Complex long double volatile *, _Complex long double ),
2576        ?/=?( _Complex long double volatile *, _Complex long double ),
2577        ?+=?( _Complex long double volatile *, _Complex long double ),
2578        ?-=?( _Complex long double volatile *, _Complex long double );
2579\end{lstlisting}
2580
2581For every extended integer type ©X© there exist
2582% Don't use predefined: keep this out of prelude.cf.
2583\begin{lstlisting}
2584?*=?( X volatile *, X ),
2585?/=?( X volatile *, X ),
2586?+=?( X volatile *, X ),
2587?-=?( X volatile *, X ),
2588?%=?( X volatile *, X ),
2589?<<=?( X volatile *, int ),
2590?>>=?( X volatile *, int ),
2591?&=?( X volatile *, X ),
2592?^=?( X volatile *, X ),
2593?|=?( X volatile *, X );
2594\end{lstlisting}
2595
2596For every complete enumerated type ©E© there exist
2597% Don't use predefined: keep this out of prelude.cf.
2598\begin{lstlisting}
2599?*=?( E volatile *, E ),
2600?/=?( E volatile *, E ),
2601?+=?( E volatile *, E ),
2602?-=?( E volatile *, E ),
2603?%=?( E volatile *, E ),
2604?<<=?( E volatile *, int ),
2605?>>=?( E volatile *, int ),
2606?&=?( E volatile *, E ),
2607?^=?( E volatile *, E ),
2608?|=?( E volatile *, E );
2609\end{lstlisting}
2610
2611
2612\subsection{Comma operator}
2613
2614\begin{syntax}
2615\lhs{expression}
2616\rhs \nonterm{assignment-expression}
2617\rhs \nonterm{expression} ©,© \nonterm{assignment-expression}
2618\end{syntax}
2619
2620\semantics
2621In the comma expression ``©a, b©'', the first operand is interpreted as ``©( void )(a)©'', which shall be unambiguous\index{ambiguous interpretation}.
2622The interpretations of the expression are the interpretations of the second operand.
2623
2624
2625\section{Constant expressions}
2626
2627
2628\section{Declarations}
2629
2630\begin{syntax}
2631\oldlhs{declaration}
2632\rhs \nonterm{type-declaration}
2633\rhs \nonterm{spec-definition}
2634\end{syntax}
2635
2636\constraints
2637If an identifier has \Index{no linkage}, there shall be no more than one declaration of the identifier ( in a declarator or type specifier ) with compatible types in the same scope and in the same name space, except that:
2638\begin{itemize}
2639\item a typedef name may be redefined to denote the same type as it currently does, provided that type is not a variably modified type;
2640\item tags may be redeclared as specified in section 6.7.2.3 of the \Celeven standard.
2641\end{itemize}
2642\begin{rationale}
2643This constraint adds the phrase ``with compatible types'' to the \Celeven constraint, to allow overloading.
2644\end{rationale}
2645
2646An identifier declared by a type declaration shall not be redeclared as a parameter in a function definition whose declarator includes an identifier list.
2647\begin{rationale}
2648This restriction echos \Celeven's ban on the redeclaration of typedef names as parameters.
2649This avoids an ambiguity between old-style function declarations and new-style function prototypes:
2650\begin{lstlisting}
2651void f( Complex,        // ... 3000 characters ...
2652void g( Complex,        // ... 3000 characters ...
2653int Complex;
2654{ ... }
2655\end{lstlisting}
2656Without the rule, ©Complex© would be a type in the first case, and a parameter name in the second.
2657\end{rationale}
2658
2659
2660\setcounter{subsection}{1}
2661\subsection{Type specifiers}
2662
2663\begin{syntax}
2664\oldlhs{type-specifier}
2665\rhs \nonterm{forall-specifier}
2666\end{syntax}
2667
2668\semantics
2669Forall specifiers are discussed in \VRef{forall}.
2670
2671
2672\subsubsection{Structure and union specifiers}
2673
2674\semantics 
2675\CFA extends the \Celeven definition of \define{anonymous structure} to include structure specifiers with tags, and extends the \Celeven definition of \define{anonymous union} to include union specifiers with tags.
2676\begin{rationale}
2677This extension imitates an extension in the Plan 9 C compiler \cite{Thompson90new}.
2678\end{rationale}
2679
2680\examples
2681\begin{lstlisting}
2682struct point {§\impl{point}§
2683        int x, y;
2684};
2685struct color_point {§\impl{color_point}§
2686        enum { RED, BLUE, GREEN } color;
2687        struct point;
2688};
2689struct color_point cp;
2690cp.x = 0;
2691cp.color = RED;
2692struct literal {§\impl{literal}§
2693        enum { NUMBER, STRING } tag;
2694        union {
2695                double n;
2696                char *s;
2697        };
2698};
2699struct literal *next;
2700int length;
2701extern int strlen( const char * );
2702...
2703if ( next->tag == STRING ) length = strlen( next->s );
2704\end{lstlisting}
2705
2706
2707\setcounter{subsubsection}{4}
2708\subsubsection{Forall specifiers}
2709\label{forall}
2710
2711\begin{syntax}
2712\lhs{forall-specifier}
2713\rhs ©forall© ©(© \nonterm{type-parameter-list} ©)©
2714\end{syntax}
2715
2716\begin{comment}
2717\constraints
2718If the \nonterm{declaration-specifiers} of a declaration that contains a \nonterm{forall-specifier} declares a structure or union tag, the types of the members of the structure or union shall not use any of the type identifiers declared by the \nonterm{type-parameter-list}.
2719\begin{rationale}
2720This sort of declaration is illegal because the scope of the type identifiers ends at the end of the declaration, but the scope of the structure tag does not.
2721\begin{lstlisting}
2722forall( otype T ) struct Pair { T a, b;
2723} mkPair( T, T ); // illegal
2724\end{lstlisting}
2725If an instance of ©struct Pair© was declared later in the current scope, what would the members' type be?
2726\end{rationale}
2727\end{comment}
2728
2729\semantics
2730The \nonterm{type-parameter-list}s and assertions of the \nonterm{forall-specifier}s declare type identifiers, function and object identifiers with \Index{no linkage}.
2731
2732If, in the declaration ``©T D©'', ©T© contains \nonterm{forall-specifier}s and ©D© has the form
2733\begin{lstlisting}
2734D( §\normalsize\nonterm{parameter-type-list}§ )
2735\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 ©D©, and it is used in the type of a parameter in the following
2736\nonterm{type-parameter-list} or it and an inferred parameter are used as arguments of a \Index{specification} in one of the \nonterm{forall-specifier}s.
2737The identifiers declared by assertions that use an inferred parameter of a function declarator are \Index{assertion parameter}s of that function declarator.
2738
2739\begin{comment}
2740\begin{rationale}
2741Since every inferred parameter is used by some parameter, inference can be understood as a single bottom-up pass over the expression tree, that only needs to apply local reasoning at each node.
2742
2743If this restriction were lifted, it would be possible to write
2744\begin{lstlisting}
2745forall( otype T ) T * alloc( void );§\use{alloc}§ int *p = alloc();
2746\end{lstlisting}
2747Here ©alloc()© would receive ©int© as an inferred argument, and return an ©int *©.
2748In general, if a call to ©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 ©T© to be bound.
2749
2750With the current restriction, ©alloc()© must be given an argument that determines ©T©:
2751\begin{lstlisting}
2752forall( otype T ) T * alloc( T initial_value );§\use{alloc}§
2753\end{lstlisting}
2754\end{rationale}
2755\end{comment}
2756
2757If a function declarator is part of a function definition, its inferred parameters and assertion parameters have \Index{block scope};
2758otherwise, identifiers declared by assertions have a \define{declaration scope}, which terminates at the end of the \nonterm{declaration}.
2759
2760A function type that has at least one inferred parameter is a \define{polymorphic function} type.
2761Function types with no inferred parameters are \define{monomorphic function} types.
2762One function type is \define{less polymorphic} than another if it has fewer inferred parameters, or if it has the same number of inferred parameters and fewer of its explicit parameters have types that depend on an inferred parameter.
2763
2764The names of inferred parameters and the order of identifiers in forall specifiers are not relevant to polymorphic function type compatibility.
2765Let $f$ and $g$ be two polymorphic function types with the same number of inferred parameters, and let $f_i$ and $g_i$ be the inferred parameters of $f$ and $g$ in their order of occurance in the function types' \nonterm{parameter-type-list}s.
2766Let $f'$ be $f$ with every occurrence of $f_i$ replaced by $g_i$, for all $i$.
2767Then $f$ and $g$ are \Index{compatible type}s if $f'$'s and $g$'s return types and parameter lists are compatible, and if for every assertion parameter of $f'$ there is an assertion parameter in $g$ with the same identifier and compatible type, and vice versa.
2768
2769\examples
2770Consider these analogous monomorphic and polymorphic declarations.
2771\begin{lstlisting}
2772int fi( int );
2773forall( otype T ) T fT( T );
2774\end{lstlisting}
2775©fi()© takes an ©int© and returns an ©int©. ©fT()© takes a ©T© and returns a ©T©, for any type ©T©.
2776\begin{lstlisting}
2777int (*pfi )( int ) = fi;
2778forall( otype T ) T (*pfT )( T ) = fT;
2779\end{lstlisting}
2780©pfi© and ©pfT© are pointers to functions. ©pfT© is not polymorphic, but the function it points at is.
2781\begin{lstlisting}
2782int (*fvpfi( void ))( int ) {
2783        return pfi;
2784}
2785forall( otype T ) T (*fvpfT( void ))( T ) {
2786        return pfT;
2787}
2788\end{lstlisting}
2789©fvpfi()© and ©fvpfT()© are functions taking no arguments and returning pointers to functions. ©fvpfT()© is monomorphic, but the function that its return value points at is polymorphic.
2790\begin{lstlisting}
2791forall( otype T ) int ( *fTpfi( T ) )( int );
2792forall( otype T ) T ( *fTpfT( T ) )( T );
2793forall( otype T, otype U ) U ( *fTpfU( T ) )( U );
2794\end{lstlisting}
2795©fTpfi()© is a polymorphic function that returns a pointer to a monomorphic function taking an integer and returning an integer.
2796It could return ©pfi©. ©fTpfT()© is subtle: it is a polymorphic function returning a \emph{monomorphic} function taking and returning
2797©T©, where ©T© is an inferred parameter of ©fTpfT()©.
2798For instance, in the expression ``©fTpfT(17)©'', ©T© is inferred to be ©int©, and the returned value would have type ©int ( * )( int )©. ``©fTpfT(17)(13)©'' and ``©fTpfT("yes")("no")©'' are legal, but ``©fTpfT(17)("no")©'' is illegal.
2799©fTpfU()© is polymorphic ( in type ©T©), and returns a pointer to a function that is polymorphic ( in type ©U©). ``©f5(17)("no")©'' is a legal expression of type ©char *©.
2800\begin{lstlisting}
2801forall( otype T, otype U, otype V ) U * f( T *, U, V * const );
2802forall( otype U, otype V, otype W ) U * g( V *, U, W * const );
2803\end{lstlisting}
2804The functions ©f()© and ©g()© have compatible types.
2805Let \(f\) and \(g\) be their types;
2806then \(f_1\) = ©T©, \(f_2\) = ©U©, \(f_3\) = ©V©, \(g_1\)
2807= ©V©, \(g_2\) = ©U©, and \(g_3\) = ©W©.
2808Replacing every \(f_i\) by \(g_i\) in \(f\) gives
2809\begin{lstlisting}
2810forall( otype V, otype U, otype W ) U * f( V *, U, W * const );
2811\end{lstlisting} which has a return type and parameter list that is compatible with \(g\).
2812\begin{rationale}
2813The word ``©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.
2814
2815Even without parameterized types, I might try to allow
2816\begin{lstlisting}
2817forall( int n ) int sum( int vector[n] );
2818\end{lstlisting} but C currently rewrites array parameters as pointer parameters, so the effects of such a change require more thought.
2819\end{rationale}
2820
2821\begin{rationale}
2822A polymorphic declaration must do two things: it must introduce type parameters, and it must apply assertions to those types.
2823Adding this to existing C declaration syntax and semantics was delicate, and not entirely successful.
2824
2825C depends on declaration-before-use, so a forall specifier must introduce type names before they can be used in the declaration specifiers.
2826This could be done by making the forall specifier part of the declaration specifiers, or by making it a new introductory clause of declarations.
2827
2828Assertions are also part of polymorphic function types, because it must be clear which functions have access to the assertion parameters declared by the assertions.
2829All attempts to put assertions inside an introductory clause produced complex semantics and confusing code.
2830Building them into the declaration specifiers could be done by placing them in the function's parameter list, or in a forall specifier that is a declaration specifier.
2831Assertions are also used with type parameters of specifications, and by type declarations.
2832For consistency's sake it seems best to attach assertions to the type declarations in forall specifiers, which means that forall specifiers must be declaration specifiers.
2833\end{rationale}
2834%HERE
2835
2836
2837\subsection{Type qualifiers}
2838
2839\CFA defines a new type qualifier ©lvalue©\impl{lvalue}\index{lvalue}.
2840\begin{syntax}
2841\oldlhs{type-qualifier}
2842\rhs ©lvalue©
2843\end{syntax}
2844
2845\constraints
2846\Indexc{restrict} Types other than type parameters and pointer types whose referenced type is an object type shall not be restrict-qualified.
2847
2848\semantics
2849An object's type may be a restrict-qualified type parameter.
2850©restrict© does not establish any special semantics in that case.
2851
2852\begin{rationale}
2853\CFA loosens the constraint on the restrict qualifier so that restrict-qualified pointers may be passed to polymorphic functions.
2854\end{rationale}
2855
2856©lvalue© may be used to qualify the return type of a function type.
2857Let ©T© be an unqualified version of a type;
2858then the result of calling a function with return type ©lvalue T© is a \Index{modifiable lvalue} of type ©T©.
2859©const©\use{const} and ©volatile©\use{volatile} qualifiers may also be added to indicate that the function result is a constant or volatile lvalue.
2860\begin{rationale}
2861The ©const© and ©volatile© qualifiers can only be sensibly used to qualify the return type of a function if the ©lvalue© qualifier is also used.
2862\end{rationale}
2863
2864An {lvalue}-qualified type may be used in a \Index{cast expression} if the operand is an lvalue;
2865the result of the expression is an lvalue.
2866
2867\begin{rationale}
2868©lvalue© provides some of the functionality of \CC's ``©T&©'' ( reference to object of type ©T©) type.
2869Reference types have four uses in \CC.
2870\begin{itemize}
2871\item
2872They are necessary for user-defined operators that return lvalues, such as ``subscript'' and ``dereference''.
2873
2874\item
2875A 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 ©with© statement.
2876The following \CC code gives an example.
2877\begin{lstlisting}
2878{
2879        char &code = long_name.some_field[i].data->code;
2880        code = toupper( code );
2881}
2882\end{lstlisting}
2883This is not very useful.
2884
2885\item
2886A reference parameter can be used to allow a function to modify an argument without forcing the caller to pass the address of the argument.
2887This is most useful for user-defined assignment operators.
2888In \CC, plain assignment is done by a function called ``©operator=©'', and the two expressions
2889\begin{lstlisting}
2890a = b;
2891operator=( a, b );
2892\end{lstlisting} are equivalent.
2893If ©a© and ©b© are of type ©T©, then the first parameter of ©operator=© must have type ``©T&©''.
2894It cannot have type ©T©, because then assignment couldn't alter the variable, and it can't have type ``©T *©'', because the assignment would have to be written ``©&a = b;©''.
2895
2896In 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 ``©a = b;©'' is equivalent to ``©operator=(&( a), b )©''.
2897Reference 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 ``©&©''.
2898
2899\item
2900References to \Index{const-qualified} types can be used instead of value parameters.  Given the
2901\CC function call ``©fiddle( a_thing )©'', where the type of ©a_thing© is
2902©Thing©, the type of ©fiddle© could be either of
2903\begin{lstlisting}
2904void fiddle( Thing );
2905void fiddle( const Thing & );
2906\end{lstlisting}
2907If 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 ©fiddle© the parameter is subject to the usual problems caused by aliases.
2908The reference form might be chosen for efficiency's sake if ©Thing©s are too large or their constructors or destructors are too expensive.
2909An implementation may switch between them without causing trouble for well-behaved clients.
2910This leaves the implementor to define ``too large'' and ``too expensive''.
2911
2912I propose to push this job onto the compiler by allowing it to implement
2913\begin{lstlisting}
2914void fiddle( const volatile Thing );
2915\end{lstlisting} with call-by-reference.
2916Since it knows all about the size of ©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''.
2917\end{itemize}
2918
2919In summary, since references are only really necessary for returning lvalues, I'll only provide lvalue functions.
2920\end{rationale}
2921
2922
2923\setcounter{subsection}{8}
2924\subsection{Initialization}
2925
2926An expression that is used as an \nonterm{initializer} is treated as being cast to the type of the object being initialized.
2927An expression used in an \nonterm{initializer-list} is treated as being cast to the type of the aggregate member that it initializes.
2928In either case the cast must have a single unambiguous \Index{interpretation}.
2929
2930
2931\setcounter{subsection}{10}
2932\subsection{Specification definitions}
2933
2934\begin{syntax}
2935\lhs{spec-definition}
2936\rhs ©spec© \nonterm{identifier} 
2937        ©(© \nonterm{type-parameter-list} ©)©
2938        ©{© \nonterm{spec-declaration-list}\opt ©}©
2939\lhs{spec-declaration-list}
2940\rhs \nonterm{spec-declaration} ©;©
2941\rhs \nonterm{spec-declaration-list} \nonterm{spec-declaration} ©;©
2942\lhs{spec-declaration}
2943\rhs \nonterm{specifier-qualifier-list} \nonterm{declarator-list}
2944\lhs{declarator-list}
2945\rhs \nonterm{declarator}
2946\rhs \nonterm{declarator-list} ©,© \nonterm{declarator}
2947\end{syntax}
2948\begin{rationale}
2949The declarations allowed in a specification are much the same as those allowed in a structure, except that bit fields are not allowed, and \Index{incomplete type}s and function types are allowed.
2950\end{rationale}
2951
2952\semantics
2953A \define{specification definition} defines a name for a \define{specification}: a parameterized collection of object and function declarations.
2954
2955The declarations in a specification consist of the declarations in the
2956\nonterm{spec-declaration-list} and declarations produced by any assertions in the
2957\nonterm{spec-parameter-list}.
2958If the collection contains two declarations that declare the same identifier and have compatible types, they are combined into one declaration with the composite type constructed from the two types.
2959
2960
2961\subsubsection{Assertions}
2962
2963\begin{syntax}
2964\lhs{assertion-list}
2965\rhs \nonterm{assertion}
2966\rhs \nonterm{assertion-list} \nonterm{assertion}
2967\lhs{assertion}
2968\rhs ©|© \nonterm{identifier} ©(© \nonterm{type-name-list} ©)©
2969\rhs ©|© \nonterm{spec-declaration}
2970\lhs{type-name-list}
2971\rhs \nonterm{type-name}
2972\rhs \nonterm{type-name-list} ©,© \nonterm{type-name}
2973\end{syntax}
2974
2975\constraints
2976The \nonterm{identifier} in an assertion that is not a \nonterm{spec-declaration} shall be the name of a specification.
2977The \nonterm{type-name-list} shall contain one \nonterm{type-name} argument for each \nonterm{type-parameter} in that specification's \nonterm{spec-parameter-list}.
2978If the
2979\nonterm{type-parameter} uses type-class ©type©\use{type}, the argument shall be the type name of an \Index{object type};
2980if it uses ©dtype©, the argument shall be the type name of an object type or an \Index{incomplete type};
2981and if it uses ©ftype©, the argument shall be the type name of a \Index{function type}.
2982
2983\semantics
2984An \define{assertion} is a declaration of a collection of objects and functions, called \define{assertion parameters}.
2985
2986The assertion parameters produced by an assertion that applies the name of a specification to type arguments are found by taking the declarations specified in the specification and treating each of the specification's parameters as a synonym for the corresponding \nonterm{type-name} argument.
2987
2988The collection of assertion parameters produced by the \nonterm{assertion-list} are found by combining the declarations produced by each assertion.
2989If the collection contains two declarations that declare the same identifier and have compatible types, they are combined into one declaration with the \Index{composite type} constructed from the two types.
2990
2991\examples
2992\begin{lstlisting}
2993forall( otype T | T ?*?( T, T ))§\use{?*?}§
2994T square( T val ) {§\impl{square}§
2995        return val + val;
2996}
2997trait summable( otype T ) {§\impl{summable}§
2998        T ?+=?( T *, T );§\use{?+=?}§
2999        const T 0;§\use{0}§
3000};
3001trait list_of( otype List, otype Element ) {§\impl{list_of}§
3002        Element car( List );
3003        List cdr( List );
3004        List cons( Element, List );
3005        List nil;
3006        int is_nil( List );
3007};
3008trait sum_list( otype List, otype Element | summable( Element ) | list_of( List, Element ) ) {};
3009\end{lstlisting}
3010©sum_list© contains seven declarations, which describe a list whose elements can be added up.
3011The assertion ``©|sum_list( i_list, int )©''\use{sum_list} produces the assertion parameters
3012\begin{lstlisting}
3013int ?+=?( int *, int );
3014const int 0;
3015int car( i_list );
3016i_list cdr( i_list );
3017i_list cons( int, i_list );
3018i_list nil;
3019int is_nil;
3020\end{lstlisting}
3021
3022
3023\subsection{Type declarations}
3024
3025\begin{syntax}
3026\lhs{type-parameter-list}
3027\rhs \nonterm{type-parameter}
3028\rhs \nonterm{type-parameter-list} ©,© \nonterm{type-parameter}
3029\lhs{type-parameter}
3030\rhs \nonterm{type-class} \nonterm{identifier} \nonterm{assertion-list}\opt
3031\lhs{type-class}
3032\rhs ©type©
3033\rhs ©dtype©
3034\rhs ©ftype©
3035\lhs{type-declaration}
3036\rhs \nonterm{storage-class-specifier}\opt ©type© \nonterm{type-declarator-list} \verb|;|
3037\lhs{type-declarator-list}
3038\rhs \nonterm{type-declarator}
3039\rhs \nonterm{type-declarator-list} ©,© \nonterm{type-declarator}
3040\lhs{type-declarator}
3041\rhs \nonterm{identifier} \nonterm{assertion-list}\opt ©=© \nonterm{type-name}
3042\rhs \nonterm{identifier} \nonterm{assertion-list}\opt
3043\end{syntax}
3044
3045\constraints
3046If a type declaration has block scope, and the declared identifier has external or internal linkage, the declaration shall have no initializer for the identifier.
3047
3048\semantics
3049A \nonterm{type-parameter} or a \nonterm{type-declarator} declares an identifier to be a \Index{type name} for a type incompatible with all other types.
3050
3051An identifier declared by a \nonterm{type-parameter} has \Index{no linkage}.
3052Identifiers declared with type-class ©type©\use{type} are \Index{object type}s;
3053those declared with type-class ©dtype©\use{dtype} are \Index{incomplete type}s;
3054and those declared with type-class ©ftype©\use{ftype} are \Index{function type}s.
3055The 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}.
3056
3057A \nonterm{type-declarator} with an \Index{initializer} is a \define{type definition}.  The declared identifier is an \Index{incomplete type} within the initializer, and an \Index{object type} after the end of the initializer.
3058The type in the initializer is called the \define{implementation
3059  type}.
3060Within 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.
3061
3062A type declaration without an \Index{initializer} and without a \Index{storage-class specifier} or with storage-class specifier ©static©\use{static} defines an \Index{incomplete type}.
3063If a \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).
3064\begin{rationale}
3065Incomplete type declarations allow compact mutually-recursive types.
3066\begin{lstlisting}
3067otype t1; // incomplete type declaration
3068otype t2 = struct { t1 * p; ... };
3069otype t1 = struct { t2 * p; ... };
3070\end{lstlisting}
3071Without them, mutual recursion could be handled by declaring mutually recursive structures, then initializing the types to those structures.
3072\begin{lstlisting}
3073struct s1;
3074otype t2 = struct s2 { struct s1 * p; ... };
3075otype t1 = struct s1 { struct s2 * p; ... };
3076\end{lstlisting}
3077This introduces extra names, and may force the programmer to cast between the types and their implementations.
3078\end{rationale}
3079
3080A type declaration without an initializer and with \Index{storage-class specifier} ©extern©\use{extern} is an \define{opaque type declaration}.
3081Opaque types are \Index{object type}s.
3082An opaque type is not a \nonterm{constant-expression};
3083neither is a structure or union that has a member whose type is not a \nonterm{constant-expression}.
3084Every other \Index{object type} is a \nonterm{constant-expression}.
3085Objects with static storage duration shall be declared with a type that is a \nonterm{constant-expression}.
3086\begin{rationale}
3087Type declarations can declare identifiers with external linkage, whereas typedef declarations declare identifiers that only exist within a translation unit.
3088These opaque types can be used in declarations, but the implementation of the type is not visible.
3089
3090Static objects can not have opaque types because space for them would have to be allocated at program start-up.
3091This is a deficiency\index{deficiencies!static opaque objects}, but I don't want to deal with ``module initialization'' code just now.
3092\end{rationale}
3093
3094An \Index{incomplete type} which is not a qualified version\index{qualified type} of a type is a value of \Index{type-class} ©dtype©.
3095An object type\index{object types} which is not a qualified version of a type is a value of type-classes ©type© and ©dtype©.
3096A \Index{function type} is a value of type-class ©ftype©.
3097\begin{rationale}
3098Syntactically, a type value is a \nonterm{type-name}, which is a declaration for an object which omits the identifier being declared.
3099
3100Object types are precisely the types that can be instantiated.
3101Type qualifiers are not included in type values because the compiler needs the information they provide at compile time to detect illegal statements or to produce efficient machine instructions.
3102For instance, the code that a compiler must generate to manipulate an object that has volatile-qualified type may be different from the code to manipulate an ordinary object.
3103
3104Type qualifiers are a weak point of C's type system.
3105Consider the standard library function ©strchr()© which, given a string and a character, returns a pointer to the first occurrence of the character in the string.
3106\begin{lstlisting}
3107char *strchr( const char *s, int c ) {§\impl{strchr}§
3108        char real_c = c; // done because c was declared as int.
3109        for ( ; *s != real_c; s++ )
3110                if ( *s == '\0' ) return NULL;
3111        return ( char * )s;
3112}
3113\end{lstlisting}
3114The parameter ©s© must be ©const char *©, because ©strchr()© might be used to search a constant string, but the return type must be ©char *©, because the result might be used to modify a non-constant string.
3115Hence the body must perform a cast, and ( even worse) ©strchr()© provides a type-safe way to attempt to modify constant strings.
3116What is needed is some way to say that ©s©'s type might contain qualifiers, and the result type has exactly the same qualifiers.
3117Polymorphic functions do not provide a fix for this deficiency\index{deficiencies!pointers to qualified types}, because type qualifiers are not part of type values.
3118Instead, overloading can be used to define ©strchr()© for each combination of qualifiers.
3119\end{rationale}
3120
3121\begin{rationale}
3122Since \Index{incomplete type}s are not type values, they can not be used as the initializer in a type declaration, or as the type of a structure or union member.
3123This prevents the declaration of types that contain each other.
3124\begin{lstlisting}
3125otype t1;
3126otype t2 = t1; // illegal: incomplete type t1
3127otype t1 = t2;
3128\end{lstlisting}
3129
3130The initializer in a file-scope declaration must be a constant expression.
3131This means type declarations can not build on opaque types, which is a deficiency\index{deficiencies!nesting opaque
3132 types}.
3133\begin{lstlisting}
3134extern otype Huge; // extended-precision integer type
3135otype Rational = struct {
3136        Huge numerator, denominator;    // illegal
3137};
3138struct Pair {
3139        Huge first, second;                             // legal
3140};
3141\end{lstlisting}
3142Without this restriction, \CFA might require ``module initialization'' code ( since ©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 ©Huge© and the translation that declares ©Rational©.
3143
3144A 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.
3145\begin{lstlisting}
3146//  File a.c:
3147        extern type t1;
3148        type t2 = struct { t1 f1; ... } // illegal
3149//  File b.c:
3150        extern type t2;
3151        type t1 = struct { t2 f2; ... } // illegal
3152\end{lstlisting}
3153\end{rationale}
3154
3155\begin{rationale}
3156Since a \nonterm{type-declaration} is a \nonterm{declaration} and not a
3157\nonterm{struct-declaration}, type declarations can not be structure members.
3158The form of
3159\nonterm{type-declaration} forbids arrays of, pointers to, and functions returning ©type©.
3160Hence the syntax of \nonterm{type-specifier} does not have to be extended to allow type-valued expressions.
3161It also side-steps the problem of type-valued expressions producing different values in different declarations.
3162
3163Since a type declaration is not a \nonterm{parameter-declaration}, functions can not have explicit type parameters.
3164This may be too restrictive, but it attempts to make compilation simpler.
3165Recall that when traditional C scanners read in an identifier, they look it up in the symbol table to determine whether or not it is a typedef name, and return a ``type'' or ``identifier'' token depending on what they find.
3166A type parameter would add a type name to the current scope.
3167The scope manipulations involved in parsing the declaration of a function that takes function pointer parameters and returns a function pointer may just be too complicated.
3168
3169Explicit type parameters don't seem to be very useful, anyway, because their scope would not include the return type of the function.
3170Consider the following attempt to define a type-safe memory allocation function.
3171\begin{lstlisting}
3172#include <stdlib.h>
3173T * new( otype T ) { return ( T * )malloc( sizeof( T) ); };
3174... int * ip = new( int );
3175\end{lstlisting}
3176This looks sensible, but \CFA's declaration-before-use rules mean that ``©T©'' in the function body refers to the parameter, but the ``©T©'' in the return type refers to the meaning of ©T© in the scope that contains ©new©;
3177it could be undefined, or a type name, or a function or variable name.
3178Nothing good can result from such a situation.
3179\end{rationale}
3180
3181\examples
3182Since type declarations create new types, instances of types are always passed by value.
3183\begin{lstlisting}
3184otype A1 = int[2];
3185void f1( A1 a ) { a[0] = 0; };
3186otypedef int A2[2];
3187void f2( A2 a ) { a[0] = 0; };
3188A1 v1;
3189A2 v2;
3190f1( v1 );
3191f2( v2 );
3192\end{lstlisting}
3193©V1© is passed by value, so ©f1()©'s assignment to ©a[0]© does not modify v1.  ©V2© is converted to a pointer, so ©f2()© modifies ©v2[0]©.
3194
3195A translation unit containing the declarations
3196\begin{lstlisting}
3197extern type Complex;§\use{Complex}§ // opaque type declaration
3198extern float abs( Complex );§\use{abs}§
3199\end{lstlisting} can contain declarations of complex numbers, which can be passed to ©abs©.
3200Some other translation unit must implement ©Complex© and ©abs©.
3201That unit might contain the declarations
3202\begin{lstlisting}
3203otype Complex = struct { float re, im; }\impl{Complex}§
3204Complex cplx_i = { 0.0, 1.0 }\impl{cplx_i}§
3205float abs( Complex c ) {§\impl{abs( Complex )}§
3206        return sqrt( c.re * c.re + c.im * c.im );
3207}
3208\end{lstlisting}
3209Note that ©c© is implicitly converted to a ©struct© so that its components can be retrieved.
3210
3211\begin{lstlisting}
3212otype Time_of_day = int;§\impl{Time_of_day}§ // seconds since midnight.
3213Time_of_day ?+?( Time_of_day t1, int seconds ) {§\impl{?+?}§
3214        return (( int)t1 + seconds ) % 86400;
3215}
3216\end{lstlisting}
3217©t1© must be cast to its implementation type to prevent infinite recursion.
3218
3219\begin{rationale}
3220Within the scope of a type definition, an instance of the type can be viewed as having that type or as having the implementation type.
3221In the ©Time_of_day© example, the difference is important.
3222Different languages have treated the distinction between the abstraction and the implementation in different ways.
3223\begin{itemize}
3224\item
3225Inside a Clu cluster \cite{CLU}, the declaration of an instance states which view applies.
3226Two primitives called ©up© and ©down© can be used to convert between the views.
3227\item
3228The Simula class \cite{SIMULA87} is essentially a record type.
3229Since 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.
3230In \CC
3231\cite{C++}, operations on class instances include assignment and ``©&©'', which can be overloaded.
3232A ``scope resolution'' operator can be used inside the class to specify whether the abstract or implementation version of the operation should be used.
3233\item
3234An 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.
3235The derived subprograms are clones of the existing subprograms with the old type replaced by the derived type.
3236Literals and aggregates of the old type are also cloned.
3237In other words, the abstract view provides exactly the same operations as the implementation view.
3238This allows the abstract view to be used in all cases.
3239
3240The derived subprograms can be replaced by programmer-specified subprograms.
3241This is an exception to the normal scope rules, which forbid duplicate definitions of a subprogram in a scope.
3242In this case, explicit conversions between the derived type and the old type can be used.
3243\end{itemize}
3244\CFA's rules are like Clu's, except that implicit conversions and conversion costs allow it to do away with most uses of ©up© and ©down©.
3245\end{rationale}
3246
3247
3248\subsubsection{Default functions and objects}
3249
3250A declaration\index{type declaration} of a type identifier ©T© with type-class ©type© implicitly declares a \define{default assignment} function ©T ?=?( T *, T )©\use{?=?}, with the same \Index{scope} and \Index{linkage} as the identifier ©T©.
3251\begin{rationale}
3252Assignment 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).
3253Without this rule, nearly every inferred type parameter would need an accompanying assignment assertion parameter.
3254If a type parameter should not have an assignment operation, ©dtype© should be used.
3255If 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.
3256\end{rationale}
3257
3258A definition\index{type definition} of a type identifier ©T© with \Index{implementation type} ©I© and type-class ©type© implicitly defines a default assignment function.
3259A definition\index{type definition} of a type identifier ©T© with implementation type ©I© and an assertion list implicitly defines \define{default function}s and \define{default object}s as declared by the assertion declarations.
3260The default objects and functions have the same \Index{scope} and \Index{linkage} as the identifier ©T©.
3261Their values are determined as follows:
3262\begin{itemize}
3263\item
3264If at the definition of ©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 ©I© replaced by ©T© is compatible with the type of the default object, then the default object is initialized with that object.
3265Otherwise the scope of the declaration of ©T© must contain a definition of the default object.
3266
3267\item 
3268If at the definition of ©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 ©I© replaced by ©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.
3269
3270Otherwise, if ©I© contains exactly one anonymous member\index{anonymous member} such that at the definition of ©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 ©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.
3271
3272Otherwise the scope of the declaration of ©T© must contain a definition of the default function.
3273\end{itemize}
3274\begin{rationale}
3275Note that a pointer to a default function will not compare as equal to a pointer to the inherited function.
3276\end{rationale}
3277
3278A 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 ©T© replaces the default function or object.
3279
3280\examples
3281\begin{lstlisting}
3282trait s( otype T ) {
3283        T a, b;
3284} struct impl { int left, right; } a = { 0, 0 };
3285otype Pair | s( Pair ) = struct impl;
3286Pair b = { 1, 1 };
3287\end{lstlisting}
3288The definition of ©Pair© implicitly defines two objects ©a© and ©b©.
3289©Pair a© inherits its value from the ©struct impl a©.
3290The definition of ©Pair b© is compulsory because there is no ©struct impl b© to construct a value from.
3291\begin{lstlisting}
3292trait ss( otype T ) {
3293        T clone( T );
3294        void munge( T * );
3295}
3296otype Whatsit | ss( Whatsit );§\use{Whatsit}§
3297otype Doodad | ss( Doodad ) = struct doodad {§\use{Doodad}§
3298        Whatsit; // anonymous member
3299        int extra;
3300};
3301Doodad clone( Doodad ) { ... }
3302\end{lstlisting}
3303The definition of ©Doodad© implicitly defines three functions:
3304\begin{lstlisting}
3305Doodad ?=?( Doodad *, Doodad );
3306Doodad clone( Doodad );
3307void munge( Doodad * );
3308\end{lstlisting}
3309The assignment function inherits ©struct doodad©'s assignment function because the types match when ©struct doodad©  is replaced by ©Doodad© throughout.
3310©munge()© inherits ©Whatsit©'s ©munge()© because the types match when ©Whatsit© is replaced by ©Doodad© in the parameter list. ©clone()© does \emph{not} inherit ©Whatsit©'s ©clone()©: replacement in the parameter list yields ``©Whatsit clone( Doodad )©'', which is not compatible with ©Doodad©'s ©clone()©'s type.
3311Hence the definition of ``©Doodad clone( Doodad )©'' is necessary.
3312
3313Default functions and objects are subject to the normal scope rules.
3314\begin{lstlisting}
3315otype T = ...;
3316T a_T = ...;            // Default assignment used.
3317T ?=?( T *, T );
3318T a_T = ...;            // Programmer-defined assignment called.
3319\end{lstlisting}
3320\begin{rationale}
3321A compiler warning would be helpful in this situation.
3322\end{rationale}
3323
3324\begin{rationale}
3325The \emph{class} construct of object-oriented programming languages performs three independent functions.
3326It \emph{encapsulates} a data structure;
3327it defines a \emph{subtype} relationship, whereby instances of one class may be used in contexts that require instances of another;
3328and it allows one class to \emph{inherit} the implementation of another.
3329
3330In \CFA, encapsulation is provided by opaque types and the scope rules, and subtyping is provided by specifications and assertions.
3331Inheritance is provided by default functions and objects.
3332\end{rationale}
3333
3334
3335\section{Statements and blocks}
3336
3337\begin{syntax}
3338\oldlhs{statement}
3339\rhs \nonterm{exception-statement}
3340\end{syntax}
3341
3342Many statements contain expressions, which may have more than one interpretation.
3343The following sections describe how the \CFA translator selects an interpretation.
3344In all cases the result of the selection shall be a single unambiguous \Index{interpretation}.
3345
3346
3347\subsection{Labeled statements}
3348
3349\begin{syntax}
3350\oldlhs{labeled-statement}
3351\rhs ©case© \nonterm{case-value-list} : \nonterm{statement}
3352\lhs{case-value-list}
3353\rhs \nonterm{case-value}
3354\rhs \nonterm{case-value-list} ©,© \nonterm{case-value}
3355\lhs{case-value}
3356\rhs \nonterm{constant-expression}
3357\rhs \nonterm{subrange}
3358\lhs{subrange}
3359\rhs \nonterm{constant-expression} ©~© \nonterm{constant-expression}
3360\end{syntax}
3361
3362The following have identical meaning:
3363\begin{lstlisting}
3364case 1:  case 2:  case 3:  case 4:  case 5:
3365case 1, 2, 3, 4, 5:
3366case 1~5:
3367\end{lstlisting}
3368Multiple subranges are allowed:
3369\begin{lstlisting}
3370case 1~4, 9~14, 27~32:
3371\end{lstlisting}
3372The ©case© and ©default© clauses are restricted within the ©switch© and ©choose© statements, precluding Duff's device.
3373
3374
3375\subsection{Expression and null statements}
3376
3377The expression in an expression statement is treated as being cast to ©void©.
3378
3379
3380\subsection{Selection statements}
3381
3382\begin{syntax}
3383\oldlhs{selection-statement}
3384\rhs ©choose© ©(© \nonterm{expression} ©)© \nonterm{statement}
3385\end{syntax}
3386
3387The controlling expression ©E© in the ©switch© and ©choose© statement:
3388\begin{lstlisting}
3389switch ( E ) ...
3390choose ( E ) ...
3391\end{lstlisting} may have more than one interpretation, but it shall have only one interpretation with an integral type.
3392An \Index{integer promotion} is performed on the expression if necessary.
3393The constant expressions in ©case© statements with the switch are converted to the promoted type.
3394
3395
3396\setcounter{subsubsection}{3}
3397\subsubsection[The choose statement]{The \lstinline@choose@ statement}
3398
3399The ©choose© statement is the same as the ©switch© statement except control transfers to the end of the ©choose© statement at a ©case© or ©default© labeled statement.
3400The ©fallthru© statement is used to fall through to the next ©case© or ©default© labeled statement.
3401The following have identical meaning:
3402\begin{flushleft}
3403\begin{tabular}{@{\hspace{2em}}l@{\hspace{2em}}l@{}}
3404\begin{lstlisting}
3405switch (...) {
3406  case 1: ... ; break;
3407  case 2: ... ; break;
3408  case 3: ... ; // fall through
3409  case 4: ... ; // fall through
3410  default: ... break;
3411}
3412\end{lstlisting}
3413&
3414\begin{lstlisting}
3415choose (...) {
3416  case 1: ... ; // exit
3417  case 2: ... ; // exit
3418  case 3: ... ; fallthru;
3419  case 4: ... ; fallthru;
3420  default: ... ; // exit
3421}
3422\end{lstlisting}
3423\end{tabular}
3424\end{flushleft}
3425The ©choose© statement addresses the problem of accidental fall-through associated with the ©switch© statement.
3426
3427
3428\subsection{Iteration statements}
3429
3430The controlling expression ©E© in the loops
3431\begin{lstlisting}
3432if ( E ) ...
3433while ( E ) ...
3434do ... while ( E );
3435\end{lstlisting}
3436is treated as ``©( int )((E)!=0)©''.
3437
3438The statement
3439\begin{lstlisting}
3440for ( a; b; c ) ...
3441\end{lstlisting} is treated as
3442\begin{lstlisting}
3443for ( ( void )( a ); ( int )(( b )!=0); ( void )( c ) ) ...
3444\end{lstlisting}
3445
3446
3447\subsection{Jump statements}
3448
3449\begin{syntax}
3450\oldlhs{jump-statement}
3451\rhs ©continue© \nonterm{identifier}\opt
3452\rhs ©break© \nonterm{identifier}\opt
3453\rhs \ldots
3454\rhs ©throw© \nonterm{assignment-expression}\opt
3455\rhs ©throwResume© \nonterm{assignment-expression}\opt \nonterm{at-expression}\opt
3456\lhs{at-expression} ©_At© \nonterm{assignment-expression}
3457\end{syntax}
3458
3459Labeled ©continue© and ©break© allow useful but restricted control-flow that reduces the need for the ©goto© statement for exiting multiple nested control-structures.
3460\begin{lstlisting}
3461L1: {                                                   // compound
3462  L2: switch ( ... ) {                  // switch
3463          case ...:
3464          L3: for ( ;; ) {                      // outer for
3465                L4: for ( ;; ) {                // inner for
3466                                continue L1;    // error: not enclosing iteration
3467                                continue L2;    // error: not enclosing iteration
3468                                continue L3;    // next iteration of outer for
3469                                continue L4;    // next iteration of inner for
3470                                break L1;               // exit compound
3471                                break L2;               // exit switch
3472                                break L3;               // exit outer for
3473                                break L4;               // exit inner for
3474                        } // for
3475                } // for
3476                break;                                  // exit switch
3477          default:
3478                break L1;                               // exit compound
3479        } // switch
3480        ...
3481} // compound
3482\end{lstlisting}
3483
3484
3485\setcounter{subsubsection}{1}
3486\subsubsection[The continue statement]{The \lstinline@continue@ statement}
3487
3488The identifier in a ©continue© statement shall name a label located on an enclosing iteration statement.
3489
3490
3491\subsubsection[The break statement]{The \lstinline@break@ statement}
3492
3493The identifier in a ©break© statement shall name a label located on an enclosing compound, selection or iteration statement.
3494
3495
3496\subsubsection[The return statement]{The \lstinline@return@ statement}
3497
3498An expression in a ©return© statement is treated as being cast to the result type of the function.
3499
3500
3501\subsubsection[The throw statement]{The \lstinline@throw@ statement}
3502
3503When an exception is raised, \Index{propagation} directs control from a raise in the source execution to a handler in the faulting execution.
3504
3505
3506\subsubsection[The throwResume statement]{The \lstinline@throwResume@ statement}
3507
3508
3509\subsection{Exception statements}
3510
3511\begin{syntax}
3512\lhs{exception-statement}
3513\rhs ©try© \nonterm{compound-statement} \nonterm{handler-list}
3514\rhs ©try© \nonterm{compound-statement} \nonterm{finally-clause}
3515\rhs ©try© \nonterm{compound-statement} \nonterm{handler-list} \nonterm{finally-clause}
3516\lhs{handler-list}
3517\rhs \nonterm{handler-clause}
3518\rhs ©catch© ©(© \ldots ©)© \nonterm{compound-statement}
3519\rhs \nonterm{handler-clause} ©catch© ©(© \ldots ©)© \nonterm{compound-statement}
3520\rhs ©catchResume© ©(© \ldots ©)© \nonterm{compound-statement}
3521\rhs \nonterm{handler-clause} ©catchResume© ©(© \ldots ©)© \nonterm{compound-statement}
3522\lhs{handler-clause}
3523\rhs ©catch© ©(© \nonterm{exception-declaration} ©)© \nonterm{compound-statement}
3524\rhs \nonterm{handler-clause} ©catch© ©(© \nonterm{exception-declaration} ©)© \nonterm{compound-statement}
3525\rhs ©catchResume© ©(© \nonterm{exception-declaration} ©)© \nonterm{compound-statement}
3526\rhs \nonterm{handler-clause} ©catchResume© ©(© \nonterm{exception-declaration} ©)© \nonterm{compound-statement}
3527\lhs{finally-clause}
3528\rhs ©finally© \nonterm{compound-statement}
3529\lhs{exception-declaration}
3530\rhs \nonterm{type-specifier}
3531\rhs \nonterm{type-specifier} \nonterm{declarator}
3532\rhs \nonterm{type-specifier} \nonterm{abstract-declarator}
3533\rhs \nonterm{new-abstract-declarator-tuple} \nonterm{identifier}
3534\rhs \nonterm{new-abstract-declarator-tuple}
3535\lhs{asynchronous-statement}
3536\rhs ©enable© \nonterm{identifier-list} \nonterm{compound-statement}
3537\rhs ©disable© \nonterm{identifier-list} \nonterm{compound-statement}
3538\end{syntax}
3539
3540\Index{Exception statement}s allow a dynamic call to a handler for \Index{recovery} (\Index{termination}) or \Index{correction} (\Index{resumption}) of an \Index{abnormal event}.
3541
3542
3543\subsubsection[The try statement]{The \lstinline@try@ statement}
3544
3545The ©try© statement is a block with associated handlers, called a \Index{guarded block};
3546all other blocks are \Index{unguarded block}s.
3547A ©goto©, ©break©, ©return©, or ©continue© statement can be used to transfer control out of a try block or handler, but not into one.
3548
3549
3550\subsubsection[The enable/disable statements]{The \lstinline@enable@/\lstinline@disable@ statements}
3551
3552The ©enable©/©disable© statements toggle delivery of \Index{asynchronous exception}s.
3553
3554
3555\setcounter{section}{9}
3556\section{Preprocessing directives}
3557
3558
3559\setcounter{subsection}{7}
3560\subsection{Predefined macro names}
3561
3562The implementation shall define the macro names ©__LINE__©, ©__FILE__©, ©__DATE__©, and ©__TIME__©, as in the \Celeven standard.
3563It shall not define the macro name ©__STDC__©.
3564
3565In addition, the implementation shall define the macro name ©__CFORALL__© to be the decimal constant 1.
3566
3567
3568\appendix
3569
3570
3571\chapter{Examples}
3572
3573
3574\section{C types}
3575This section gives example specifications for some groups of types that are important in the C language, in terms of the predefined operations that can be applied to those types.
3576
3577
3578\subsection{Scalar, arithmetic, and integral types}
3579
3580The pointer, integral, and floating-point types are all \define{scalar types}.
3581All of these types can be logically negated and compared.
3582The assertion ``©scalar( Complex )©'' should be read as ``type ©Complex© is scalar''.
3583\begin{lstlisting}
3584trait scalar( otype T ) {§\impl{scalar}§
3585        int !?( T );
3586        int ?<?( T, T ), ?<=?( T, T ), ?==?( T, T ), ?>=?( T, T ), ?>?( T, T ), ?!=?( T, T );
3587};
3588\end{lstlisting}
3589
3590The integral and floating-point types are \define{arithmetic types}, which support the basic arithmetic operators.
3591The use of an assertion in the \nonterm{spec-parameter-list} declares that, in order to be arithmetic, a type must also be scalar ( and hence that scalar operations are available ).
3592This is equivalent to inheritance of specifications.
3593\begin{lstlisting}
3594trait arithmetic( otype T | scalar( T ) ) {§\impl{arithmetic}§§\use{scalar}§
3595        T +?( T ), -?( T );
3596        T ?*?( T, T ), ?/?( T, T ), ?+?( T, T ), ?-?( T, T );
3597};
3598\end{lstlisting}
3599
3600The various flavors of ©char© and ©int© and the enumerated types make up the \define{integral types}.
3601\begin{lstlisting}
3602trait integral( otype T | arithmetic( T ) ) {§\impl{integral}§§\use{arithmetic}§
3603        T ~?( T );
3604        T ?&?( T, T ), ?|?( T, T ), ?^?( T, T );
3605        T ?%?( T, T );
3606        T ?<<?( T, T ), ?>>?( T, T );
3607};
3608\end{lstlisting}
3609
3610
3611\subsection{Modifiable types}
3612\index{modifiable lvalue}
3613
3614The only operation that can be applied to all modifiable lvalues is simple assignment.
3615\begin{lstlisting}
3616trait m_lvalue( otype T ) {§\impl{m_lvalue}§
3617        T ?=?( T *, T );
3618};
3619\end{lstlisting}
3620
3621Modifiable scalar lvalues are scalars and are modifiable lvalues, and assertions in the
3622\nonterm{spec-parameter-list} reflect those relationships.
3623This is equivalent to multiple inheritance of specifications.
3624Scalars can also be incremented and decremented.
3625\begin{lstlisting}
3626trait m_l_scalar( otype T | scalar( T ) | m_lvalue( T ) ) {§\impl{m_l_scalar}§
3627        T ?++( T * ), ?--( T * );§\use{scalar}§§\use{m_lvalue}§
3628        T ++?( T * ), --?( T * );
3629};
3630\end{lstlisting}
3631
3632Modifiable arithmetic lvalues are both modifiable scalar lvalues and arithmetic.
3633Note that this results in the ``inheritance'' of ©scalar© along both paths.
3634\begin{lstlisting}
3635trait m_l_arithmetic( otype T | m_l_scalar( T ) | arithmetic( T ) ) {§\impl{m_l_arithmetic}§
3636        T ?/=?( T *, T ), ?*=?( T *, T );§\use{m_l_scalar}§§\use{arithmetic}§
3637        T ?+=?( T *, T ), ?-=?( T *, T );
3638};
3639trait m_l_integral( otype T | m_l_arithmetic( T ) | integral( T ) ) {§\impl{m_l_integral}§
3640        T ?&=?( T *, T ), ?|=?( T *, T ), ?^=?( T *, T );§\use{m_l_arithmetic}§
3641        T ?%=?( T *, T ), ?<<=?( T *, T ), ?>>=?( T *, T );§\use{integral}§
3642};
3643\end{lstlisting}
3644
3645
3646\subsection{Pointer and array types}
3647
3648Array types can barely be said to exist in \Celeven, since in most cases an array name is treated as a constant pointer to the first element of the array, and the subscript expression ``©a[i]©'' is equivalent to the dereferencing expression ``©(*( a+( i )))©''.
3649Technically, pointer arithmetic and pointer comparisons other than ``©==©'' and ``©!=©'' are only defined for pointers to array elements, but the type system does not enforce those restrictions.
3650Consequently, there is no need for a separate ``array type'' specification.
3651
3652Pointer types are scalar types.
3653Like other scalar types, they have ``©+©'' and ``©-©'' operators, but the types do not match the types of the operations in ©arithmetic©, so these operators cannot be consolidated in ©scalar©.
3654\begin{lstlisting}
3655trait pointer( type P | scalar( P ) ) {§\impl{pointer}§§\use{scalar}§
3656        P ?+?( P, long int ), ?+?( long int, P ), ?-?( P, long int );
3657        ptrdiff_t ?-?( P, P );
3658};
3659trait m_l_pointer( type P | pointer( P ) | m_l_scalar( P ) ) {§\impl{m_l_pointer}§
3660        P ?+=?( P *, long int ), ?-=?( P *, long int );
3661        P ?=?( P *, void * );
3662        void * ?=?( void **, P );
3663};
3664\end{lstlisting}
3665
3666Specifications 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.
3667Different specifications are needed for each set of \Index{type qualifier}s, because qualifiers are not included in types.
3668The assertion ``©|ptr_to( Safe_pointer, int )©'' should be read as ``©Safe_pointer© acts like a pointer to ©int©''.
3669\begin{lstlisting}
3670trait ptr_to( otype P | pointer( P ), otype T ) {§\impl{ptr_to}§§\use{pointer}§
3671        lvalue T *?( P );
3672        lvalue T ?[?]( P, long int );
3673};
3674trait ptr_to_const( otype P | pointer( P ), otype T ) {§\impl{ptr_to_const}§
3675        const lvalue T *?( P );
3676        const lvalue T ?[?]( P, long int );§\use{pointer}§
3677};
3678trait ptr_to_volatile( otype P | pointer( P ), otype T ) }§\impl{ptr_to_volatile}§
3679        volatile lvalue T *?( P );
3680        volatile lvalue T ?[?]( P, long int );§\use{pointer}§
3681};
3682trait ptr_to_const_volatile( otype P | pointer( P ), otype T ) }§\impl{ptr_to_const_volatile}§
3683        const volatile lvalue T *?( P );§\use{pointer}§
3684        const volatile lvalue T ?[?]( P, long int );
3685};
3686\end{lstlisting}
3687
3688Assignment 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 ``©T *©'' can be assigned to a ``©const T *©'', a ``©volatile T *©'', and a ``©const volatile T *©''.
3689Again, the pointed-at type is passed in, so that assertions can connect these specifications to the ``©ptr_to©'' specifications.
3690\begin{lstlisting}
3691trait 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}§ {
3692        P ?=?( P *, T * );
3693        T * ?=?( T **, P );
3694};
3695trait 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}§) {
3696        P ?=?( P *, const T * );
3697        const T * ?=?( const T **, P );
3698};
3699trait 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}§
3700        P ?=?( P *, volatile T * );
3701        volatile T * ?=?( volatile T **, P );
3702};
3703trait 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}§
3704                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}§
3705        P ?=?( P *, const volatile T * );
3706        const volatile T * ?=?( const volatile T **, P );
3707};
3708\end{lstlisting}
3709
3710Note the regular manner in which type qualifiers appear in those specifications.
3711An 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.
3712\begin{lstlisting}
3713trait 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 ) ) {
3714        MyP ?=?( MyP *, CP );
3715        CP ?=?( CP *, MyP );
3716};
3717\end{lstlisting}
3718The assertion ``©| m_l_ptr_like( Safe_ptr, const int * )©'' should be read as ``©Safe_ptr© is a pointer type like ©const int *©''.
3719This specification has two defects, compared to the original four: there is no automatic assertion that dereferencing a ©MyP© produces an lvalue of the type that ©CP© points at, and the ``©|m_l_pointer( CP )©'' assertion provides only a weak assurance that the argument passed to ©CP© really is a pointer type.
3720
3721
3722\section{Relationships between operations}
3723
3724Different operators often have related meanings;
3725for instance, in C, ``©+©'', ``©+=©'', and the two versions of ``©++©'' perform variations of addition.
3726Languages 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.
3727Completeness and consistency is left to the good taste and discretion of the programmer.
3728It is possible to encourage these attributes by providing generic operator functions, or member functions of abstract classes, that are defined in terms of other, related operators.
3729
3730In \CFA, polymorphic functions provide the equivalent of these generic operators, and specifications explicitly define the minimal implementation that a programmer should provide.
3731This section shows a few examples.
3732
3733
3734\subsection{Relational and equality operators}
3735
3736The different comparison operators have obvious relationships, but there is no obvious subset of the operations to use in the implementation of the others.
3737However, 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;
3738the library function ©strcmp© is an example.
3739
3740C and \CFA have an extra, non-obvious comparison operator: ``©!©'', logical negation, returns 1 if its operand compares equal to 0, and 0 otherwise.
3741\begin{lstlisting}
3742trait comparable( otype T ) {
3743        const T 0;
3744        int compare( T, T );
3745}
3746forall( otype T | comparable( T ) ) int ?<?( T l, T r ) {
3747        return compare( l, r ) < 0;
3748}
3749// ... similarly for <=, ==, >=, >, and !=.
3750forall( otype T | comparable( T ) ) int !?( T operand ) {
3751        return !compare( operand, 0 );
3752}
3753\end{lstlisting}
3754
3755
3756\subsection{Arithmetic and integer operations}
3757
3758A complete arithmetic type would provide the arithmetic operators and the corresponding assignment operators.
3759Of these, the assignment operators are more likely to be implemented directly, because it is usually more efficient to alter the contents of an existing object than to create and return a new one.
3760Similarly, a complete integral type would provide integral operations based on integral assignment operations.
3761\begin{lstlisting}
3762trait arith_base( otype T ) {
3763        const T 1;
3764        T ?+=?( T *, T ), ?-=?( T *, T ), ?*=?( T *, T ), ?/=?( T *, T );
3765}
3766forall( otype T | arith_base( T ) ) T ?+?( T l, T r ) {
3767        return l += r;
3768}
3769forall( otype T | arith_base( T ) ) T ?++( T * operand ) {
3770        T temporary = *operand;
3771        *operand += 1;
3772        return temporary;
3773}
3774forall( otype T | arith_base( T ) ) T ++?( T * operand ) {
3775        return *operand += 1;
3776}
3777// ... similarly for -, --, *, and /.
3778trait int_base( otype T ) {
3779        T ?&=?( T *, T ), ?|=?( T *, T ), ?^=?( T *, T );
3780        T ?%=?( T *, T ), ?<<=?( T *, T ), ?>>=?( T *, T );
3781}
3782forall( otype T | int_base( T ) ) T ?&?( T l, T r ) {
3783        return l &= r;
3784}
3785// ... similarly for |, ^, %, <<, and >>.
3786\end{lstlisting}
3787
3788Note 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 ©int_base©, ©arith_base© and ©comparable©.
3789Note also that these declarations provide guidance and assistance, but they do not define an absolutely minimal set of requirements.
3790A truly minimal implementation of an arithmetic type might only provide ©0©, ©1©, and ©?-=?©, which would be used by polymorphic ©?+=?©, ©?*=?©, and ©?/=?© functions.
3791
3792Note also that ©short© is an integer type in C11 terms, but has no operations!
3793
3794
3795\chapter{TODO}
3796Review index entries.
3797
3798Restrict allowed to qualify anything, or type/dtype parameters, but only affects pointers.
3799This gets into ©noalias© territory.
3800Qualifying anything (``©short restrict rs©'') means pointer parameters of ©?++©, etc, would need restrict qualifiers.
3801
3802Enumerated types.
3803Constants are not ints.
3804Overloading.
3805Definition should be ``representable as an integer type'', not ``as an int''.
3806C11 usual conversions freely convert to and from ordinary integer types via assignment, which works between any integer types.
3807Does enum Color ?*?( enum
3808Color, enum Color ) really make sense? ?++ does, but it adds (int)1.
3809
3810Operators on {,signed,unsigned} char and other small types. ©?<?© harmless;
3811?*? questionable for chars.
3812Generic selections make these choices visible.
3813Safe conversion operators? Predefined ``promotion'' function?
3814
3815©register© assignment might be handled as assignment to a temporary with copying back and forth, but copying must not be done by assignment.
3816
3817Don't use ©ptrdiff_t© by name in the predefineds.
3818
3819Polymorphic objects.
3820Polymorphic typedefs and type declarations.
3821
3822
3823\bibliographystyle{plain}
3824\bibliography{cfa}
3825
3826
3827\addcontentsline{toc}{chapter}{\indexname} % add index name to table of contents
3828\begin{theindex}
3829Italic page numbers give the location of the main entry for the referenced term.
3830Plain page numbers denote uses of the indexed term.
3831Entries for grammar non-terminals are italicized.
3832A typewriter font is used for grammar terminals and program identifiers.
3833\indexspace
3834\input{refrat.ind}
3835\end{theindex}
3836
3837
3838\end{document}
3839
3840% Local Variables: %
3841% tab-width: 4 %
3842% fill-column: 100 %
3843% compile-command: "make" %
3844% End: %
Note: See TracBrowser for help on using the repository browser.