Changes in doc/refrat/refrat.tex [7937abf:e945826]
- File:
-
- 1 edited
-
doc/refrat/refrat.tex (modified) (160 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/refrat/refrat.tex
r7937abf re945826 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%``%% 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 %% 2 3 %% Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo 3 4 %% … … 10 11 %% Created On : Wed Apr 6 14:52:25 2016 11 12 %% Last Modified By : Peter A. Buhr 12 %% Last Modified On : Tue May 3 18:00:28201613 %% Update Count : 6413 %% Last Modified On : Sat Apr 30 13:45:40 2016 14 %% Update Count : 29 14 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15 16 16 17 % requires tex packages: texlive-base texlive-latex-base tex-common texlive-humanities texlive-latex-extra texlive-fonts-recommended 17 18 18 % inline code ©...© (copyright symbol) emacs: C-q M-)19 % red highlighting ®...® (registered trademark sumbol) emacs: C-q M-.20 % latex escape §...§ (section symbol) emacs: C-q M-'21 % keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^19 % red highlighting ®...® (registered trademark sumbol) 20 % blue highlighting ©...© (copyright symbol) 21 % latex escape §...§ (section symbol) 22 % keyword escape ¶...¶ (pilcrow symbol) 22 23 % math escape $...$ (dollar symbol) 23 24 … … 26 27 27 28 % Latex packages used in the document. 28 \usepackage[T1]{fontenc} % allow Latin1 (extended ASCII) characters29 \usepackage{textcomp}30 \usepackage[latin1]{inputenc}31 \usepackage{upquote}32 29 \usepackage{fullpage,times} 33 \usepackage{epic,eepic}34 30 \usepackage{xspace} 35 31 \usepackage{varioref} … … 51 47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 52 48 53 % Names used in the document.54 55 \newcommand{\Version}{1.0.0}56 57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%58 59 49 \setcounter{secnumdepth}{3} % number subsubsections 60 50 \setcounter{tocdepth}{3} % subsubsections in table of contents … … 139 129 \subsection{Scopes of identifiers}\index{scopes} 140 130 141 \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. 142 The outer declaration is hidden if the two declarations have \Index{compatible type}, or if one declares an array type and the other declares a pointer type and the element type and pointed-at type are compatible, or if one has function type and the other is a pointer to a compatible function type, or if one declaration is a ©type©\use{type} or ©typedef©\use{typedef} declaration and the other is not. 143 The outer declaration becomes \Index{visible} when the scope of the inner declaration terminates. 144 \begin{rationale} 145 Hence, a \CFA program can declare an ©int v© and a ©float v© in the same scope; 131 \CFA's scope rules differ from C's in one major respect: a declaration of an identifier may overload\index{overloading} outer declarations of lexically identical identifiers in the same 132 \Index{name space}, instead of hiding them. 133 The outer declaration is hidden if the two declarations have \Index{compatible type}, or if one declares an array type and the other declares a pointer type and the element type and pointed-at type are compatible, or if one has function type and the other is a pointer to a compatible function type, or if one declaration is a \lstinline@type@\use{type} or 134 \lstinline@typedef@\use{typedef} declaration and the other is not. The outer declaration becomes 135 \Index{visible} when the scope of the inner declaration terminates. 136 \begin{rationale} 137 Hence, a \CFA program can declare an \lstinline@int v@ and a \lstinline@float v@ in the same scope; 146 138 a {\CC} program can not. 147 139 \end{rationale} … … 152 144 153 145 \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. 154 Instead, 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. 146 Instead, 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 147 \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. 155 148 Within one translation unit, each instance of an identifier with \Index{internal linkage} denotes the same object or function in the same circumstances. 156 149 Identifiers with \Index{no linkage} always denote unique entities. 157 150 \begin{rationale} 158 A \CFA program can declare an ©extern int v© and an ©extern float v©;151 A \CFA program can declare an \lstinline@extern int v@ and an \lstinline@extern float v@; 159 152 a C program cannot. 160 153 \end{rationale} … … 179 172 \end{lstlisting} 180 173 181 The type parameters in an instantiation of a generic type must satisfy any constraints in the forall specifier on the type generator declaration, e.g., ©sumable©.174 The type parameters in an instantiation of a generic type must satisfy any constraints in the forall specifier on the type generator declaration, e.g., \lstinline@sumable@. 182 175 The instantiation then has the semantics that would result if the type parameters were substituted into the type generator declaration by macro substitution. 183 176 … … 227 220 \CFA defines situations where values of one type are automatically converted to another type. 228 221 These conversions are called \define{implicit conversion}s. 229 The programmer can request \define{explicit conversion}s using cast expressions. 222 The programmer can request 223 \define{explicit conversion}s using cast expressions. 230 224 231 225 … … 239 233 In \CFA, these conversions play a role in overload resolution, and collectively are called the \define{safe arithmetic conversion}s. 240 234 241 Let ©int$_r$© and ©unsigned$_r$©be the signed and unsigned integer types with integer conversion rank\index{integer conversion rank}\index{rank|see{integer conversion rank}} $r$.242 Let ©unsigned$_{mr}$©be the unsigned integer type with maximal rank.235 Let \lstinline@int$_r$@ and \lstinline@unsigned$_r$@ be the signed and unsigned integer types with integer conversion rank\index{integer conversion rank}\index{rank|see{integer conversion rank}} $r$. 236 Let \lstinline@unsigned$_{mr}$@ be the unsigned integer type with maximal rank. 243 237 244 238 The following conversions are \emph{direct} safe arithmetic conversions. … … 247 241 The \Index{integer promotion}s. 248 242 \item 249 For every rank $r$ greater than or equal to the rank of ©int©, conversion from ©int$_r$© to ©unsigned$_r$©.250 \item 251 For 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}$©.252 \item 253 Conversion from ©unsigned$_{mr}$© to ©float©.243 For every rank $r$ greater than or equal to the rank of \lstinline@int@, conversion from \lstinline@int$_r$@ to \lstinline@unsigned$_r$@. 244 \item 245 For every rank $r$ greater than or equal to the rank of \lstinline@int@, where \lstinline@int$_{r+1}$@ exists and can represent all values of \lstinline@unsigned$_r$@, conversion from \lstinline@unsigned$_r$@ to \lstinline@int$_{r+1}$@. 246 \item 247 Conversion from \lstinline@unsigned$_{mr}$@ to \lstinline@float@. 254 248 \item 255 249 Conversion from an enumerated type to its compatible integer type. 256 250 \item 257 Conversion from ©float© to ©double©, and from ©double© to ©long double©.258 \item 259 Conversion from ©float _Complex© to ©double _Complex©, and from ©double _Complex© to ©long double _Complex©.251 Conversion from \lstinline@float@ to \lstinline@double@, and from \lstinline@double@ to \lstinline@long double@. 252 \item 253 Conversion from \lstinline@float _Complex@ to \lstinline@double _Complex@, and from \lstinline@double _Complex@ to \lstinline@long double _Complex@. 260 254 \begin{sloppypar} 261 255 \item 262 Conversion from ©float _Imaginary© to ©double _Imaginary©, and from ©double _Imaginary© to ©long double _Imaginary©, if the implementation supports imaginary types.256 Conversion from \lstinline@float _Imaginary@ to \lstinline@double _Imaginary@, and from \lstinline@double _Imaginary@ to \lstinline@long double _Imaginary@, if the implementation supports imaginary types. 263 257 \end{sloppypar} 264 258 \end{itemize} 265 259 266 If 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.260 If type \lstinline@T@ can be converted to type \lstinline@U@ by a safe direct arithmetic conversion and type \lstinline@U@ can be converted to type \lstinline@V@ by a safe arithmetic conversion, then the conversion from \lstinline@T@ to type \lstinline@V@ is an \emph{indirect} safe arithmetic conversion. 267 261 268 262 \begin{rationale} … … 278 272 \label{anon-conv} 279 273 280 If 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. 274 If an expression's type is a pointer to a structure or union type that has a member that is an 275 \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. 281 276 The result of the conversion is a pointer to the member. 282 277 … … 296 291 move_to( &cp1, &cp2 ); 297 292 \end{lstlisting} 298 Thanks to implicit conversion, the two arguments that ©move_by()© receives are pointers to ©cp1©'s second member and ©cp2©'s second member. 293 Thanks to implicit conversion, the two arguments that \lstinline@move_by()@ receives are pointers to 294 \lstinline@cp1@'s second member and \lstinline@cp2@'s second member. 299 295 300 296 … … 338 334 a direct safe arithmetic conversion; 339 335 \item 340 from any object type or incomplete type to ©void©;341 \item 342 from a pointer to any non- ©void© type to a pointer to ©void©;336 from any object type or incomplete type to \lstinline@void@; 337 \item 338 from a pointer to any non-\lstinline@void@ type to a pointer to \lstinline@void@; 343 339 \item 344 340 from a pointer to any type to a pointer to a more qualified version of the type\index{qualified type}; … … 351 347 Conversions that are not safe conversions are \define{unsafe conversion}s. 352 348 \begin{rationale} 353 As in C, there is an implicit conversion from ©void *©to any pointer type.349 As in C, there is an implicit conversion from \lstinline@void *@ to any pointer type. 354 350 This is clearly dangerous, and {\CC} does not have this implicit conversion. 355 351 \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. … … 377 373 \begin{itemize} 378 374 \item 379 The cost of an implicit conversion from ©int© to ©long© is 1. 380 The 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©. 381 382 \item 383 If ©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©. 384 Otherwise, ©unsigned short© is converted directly to ©unsigned©, and the cost is 1. 385 386 \item 387 If ©long© can represent all the values of ©unsigned©, then the conversion cost of ©unsigned© to ©long© is 1. 375 The cost of an implicit conversion from \lstinline@int@ to \lstinline@long@ is 1. 376 The cost of an implicit conversion from \lstinline@long@ to \lstinline@double@ is 3, because it is defined in terms of conversions from \lstinline@long@ to \lstinline@unsigned long@, then to \lstinline@float@, and then to \lstinline@double@. 377 378 \item 379 If \lstinline@int@ can represent all the values of \lstinline@unsigned short@, then the cost of an implicit conversion from \lstinline@unsigned short@ to \lstinline@unsigned@ is 2: 380 \lstinline@unsigned short@ to \lstinline@int@ to \lstinline@unsigned@. 381 Otherwise, \lstinline@unsigned short@ is converted directly to \lstinline@unsigned@, and the cost is 1. 382 383 \item 384 If \lstinline@long@ can represent all the values of \lstinline@unsigned@, then the conversion cost of \lstinline@unsigned@ to \lstinline@long@ is 1. 388 385 Otherwise, the conversion is an unsafe conversion, and its conversion cost is undefined. 389 386 \end{itemize} … … 393 390 \begin{syntax} 394 391 \oldlhs{keyword} 395 \rhs ©forall©396 \rhs ©lvalue©397 \rhs ©trait©398 \rhs ©dtype©399 \rhs ©ftype©400 \rhs ©otype©392 \rhs \lstinline@forall@ 393 \rhs \lstinline@lvalue@ 394 \rhs \lstinline@trait@ 395 \rhs \lstinline@dtype@ 396 \rhs \lstinline@ftype@ 397 \rhs \lstinline@otype@ 401 398 \end{syntax} 402 399 … … 405 402 406 403 \CFA allows operator \Index{overloading} by associating operators with special function identifiers. 407 Furthermore, 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.404 Furthermore, the constants ``\lstinline@0@'' and ``\lstinline@1@'' have special status for many of C's data types (and for many programmer-defined data types as well), so \CFA treats them as overloadable identifiers. 408 405 Programmers can use these identifiers to declare functions and objects that implement operators and constants for their own types. 409 406 … … 414 411 \begin{syntax} 415 412 \oldlhs{identifier} 416 \rhs ©0©417 \rhs ©1©413 \rhs \lstinline@0@ 414 \rhs \lstinline@1@ 418 415 \end{syntax} 419 416 420 \index{constant identifiers}\index{identifiers!for constants} The tokens `` ©0©''\impl{0} and ``©1©''\impl{1} are identifiers.417 \index{constant identifiers}\index{identifiers!for constants} The tokens ``\lstinline@0@''\impl{0} and ``\lstinline@1@''\impl{1} are identifiers. 421 418 No other tokens defined by the rules for integer constants are considered to be identifiers. 422 419 \begin{rationale} 423 Why `` ©0©'' and ``©1©''? Those integers have special status in C.420 Why ``\lstinline@0@'' and ``\lstinline@1@''? Those integers have special status in C. 424 421 All scalar types can be incremented and decremented, which is defined in terms of adding or subtracting 1. 425 The operations `` ©&&©'', ``©||©'', and ``©!©'' can be applied to any scalar arguments, and are defined in terms of comparison against 0.422 The operations ``\lstinline@&&@'', ``\lstinline@||@'', and ``\lstinline@!@'' can be applied to any scalar arguments, and are defined in terms of comparison against 0. 426 423 A \nonterm{constant-expression} that evaluates to 0 is effectively compatible with every pointer type. 427 424 428 425 In C, the integer constants 0 and 1 suffice because the integer promotion rules can convert them to any arithmetic type, and the rules for pointer expressions treat constant expressions evaluating to 0 as a special case. 429 426 However, user-defined arithmetic types often need the equivalent of a 1 or 0 for their functions or operators, polymorphic functions often need 0 and 1 constants of a type matching their polymorphic parameters, and user-defined pointer-like types may need a null value. 430 Defining special constants for a user-defined type is more efficient than defining a conversion to the type from ©_Bool©.431 432 Why \emph{just} `` ©0©'' and ``©1©''? Why not other integers? No other integers have special status in C.433 A facility that let programmers declare specific constants---`` ©const Rational 12©'', for instance---would not be much of an improvement.427 Defining special constants for a user-defined type is more efficient than defining a conversion to the type from \lstinline@_Bool@. 428 429 Why \emph{just} ``\lstinline@0@'' and ``\lstinline@1@''? Why not other integers? No other integers have special status in C. 430 A facility that let programmers declare specific constants---``\lstinline@const Rational 12@'', for instance---would not be much of an improvement. 434 431 Some facility for defining the creation of values of programmer-defined types from arbitrary integer tokens would be needed. 435 432 The complexity of such a feature doesn't seem worth the gain. … … 447 444 \begin{tabular}[t]{ll} 448 445 %identifier & operation \\ \hline 449 ©?[?]©& subscripting \impl{?[?]}\\450 ©?()©& function call \impl{?()}\\451 ©?++©& postfix increment \impl{?++}\\452 ©?--©& postfix decrement \impl{?--}\\453 ©++?©& prefix increment \impl{++?}\\454 ©--?©& prefix decrement \impl{--?}\\455 ©*?©& dereference \impl{*?}\\456 ©+?©& unary plus \impl{+?}\\457 ©-?©& arithmetic negation \impl{-?}\\458 ©~?©& bitwise negation \impl{~?}\\459 ©!?©& logical complement \impl{"!?}\\460 ©?*?©& multiplication \impl{?*?}\\461 ©?/?©& division \impl{?/?}\\446 \lstinline@?[?]@ & subscripting \impl{?[?]}\\ 447 \lstinline@?()@ & function call \impl{?()}\\ 448 \lstinline@?++@ & postfix increment \impl{?++}\\ 449 \lstinline@?--@ & postfix decrement \impl{?--}\\ 450 \lstinline@++?@ & prefix increment \impl{++?}\\ 451 \lstinline@--?@ & prefix decrement \impl{--?}\\ 452 \lstinline@*?@ & dereference \impl{*?}\\ 453 \lstinline@+?@ & unary plus \impl{+?}\\ 454 \lstinline@-?@ & arithmetic negation \impl{-?}\\ 455 \lstinline@~?@ & bitwise negation \impl{~?}\\ 456 \lstinline@!?@ & logical complement \impl{"!?}\\ 457 \lstinline@?*?@ & multiplication \impl{?*?}\\ 458 \lstinline@?/?@ & division \impl{?/?}\\ 462 459 \end{tabular}\hfil 463 460 \begin{tabular}[t]{ll} 464 461 %identifier & operation \\ \hline 465 ©?%?©& remainder \impl{?%?}\\466 ©?+?©& addition \impl{?+?}\\467 ©?-?©& subtraction \impl{?-?}\\468 ©?<<?©& left shift \impl{?<<?}\\469 ©?>>?©& right shift \impl{?>>?}\\470 ©?<?©& less than \impl{?<?}\\471 ©?<=?©& less than or equal \impl{?<=?}\\472 ©?>=?©& greater than or equal \impl{?>=?}\\473 ©?>?©& greater than \impl{?>?}\\474 ©?==?©& equality \impl{?==?}\\475 ©?!=?©& inequality \impl{?"!=?}\\476 ©?&?©& bitwise AND \impl{?&?}\\462 \lstinline@?%?@ & remainder \impl{?%?}\\ 463 \lstinline@?+?@ & addition \impl{?+?}\\ 464 \lstinline@?-?@ & subtraction \impl{?-?}\\ 465 \lstinline@?<<?@ & left shift \impl{?<<?}\\ 466 \lstinline@?>>?@ & right shift \impl{?>>?}\\ 467 \lstinline@?<?@ & less than \impl{?<?}\\ 468 \lstinline@?<=?@ & less than or equal \impl{?<=?}\\ 469 \lstinline@?>=?@ & greater than or equal \impl{?>=?}\\ 470 \lstinline@?>?@ & greater than \impl{?>?}\\ 471 \lstinline@?==?@ & equality \impl{?==?}\\ 472 \lstinline@?!=?@ & inequality \impl{?"!=?}\\ 473 \lstinline@?&?@ & bitwise AND \impl{?&?}\\ 477 474 \end{tabular}\hfil 478 475 \begin{tabular}[t]{ll} 479 476 %identifier & operation \\ \hline 480 ©?^?©& exclusive OR \impl{?^?}\\481 ©?|?©& inclusive OR \impl{?"|?}\\482 ©?=?©& simple assignment \impl{?=?}\\483 ©?*=?©& multiplication assignment \impl{?*=?}\\484 ©?/=?©& division assignment \impl{?/=?}\\485 ©?%=?©& remainder assignment \impl{?%=?}\\486 ©?+=?©& addition assignment \impl{?+=?}\\487 ©?-=?©& subtraction assignment \impl{?-=?}\\488 ©?<<=?©& left-shift assignment \impl{?<<=?}\\489 ©?>>=?©& right-shift assignment \impl{?>>=?}\\490 ©?&=?©& bitwise AND assignment \impl{?&=?}\\491 ©?^=?©& exclusive OR assignment \impl{?^=?}\\492 ©?|=?©& inclusive OR assignment \impl{?"|=?}\\477 \lstinline@?^?@ & exclusive OR \impl{?^?}\\ 478 \lstinline@?|?@ & inclusive OR \impl{?"|?}\\ 479 \lstinline@?=?@ & simple assignment \impl{?=?}\\ 480 \lstinline@?*=?@ & multiplication assignment \impl{?*=?}\\ 481 \lstinline@?/=?@ & division assignment \impl{?/=?}\\ 482 \lstinline@?%=?@ & remainder assignment \impl{?%=?}\\ 483 \lstinline@?+=?@ & addition assignment \impl{?+=?}\\ 484 \lstinline@?-=?@ & subtraction assignment \impl{?-=?}\\ 485 \lstinline@?<<=?@ & left-shift assignment \impl{?<<=?}\\ 486 \lstinline@?>>=?@ & right-shift assignment \impl{?>>=?}\\ 487 \lstinline@?&=?@ & bitwise AND assignment \impl{?&=?}\\ 488 \lstinline@?^=?@ & exclusive OR assignment \impl{?^=?}\\ 489 \lstinline@?|=?@ & inclusive OR assignment \impl{?"|=?}\\ 493 490 \end{tabular} 494 491 \hfil … … 505 502 506 503 \begin{rationale} 507 The 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 a508 \CFA compiler detects a syntax error because it treats `` ©?--©'' as an identifier, not as the two tokens ``©?©'' and ``©--©''.504 The use of ``\lstinline@?@'' in identifiers means that some C programs are not \CFA programs. For instance, the sequence of characters ``\lstinline@(i < 0)?--i:i@'' is legal in a C program, but a 505 \CFA compiler detects a syntax error because it treats ``\lstinline@?--@'' as an identifier, not as the two tokens ``\lstinline@?@'' and ``\lstinline@--@''. 509 506 \end{rationale} 510 507 … … 513 510 \begin{itemize} 514 511 \item 515 The logical operators ``©&&©'' and ``©||©'', and the conditional operator ``©?:©''. 512 The logical operators ``\lstinline@&&@'' and ``\lstinline@||@'', and the conditional operator 513 ``\lstinline@?:@''. 516 514 These operators do not always evaluate their operands, and hence can not be properly defined by functions unless some mechanism like call-by-name is added to the language. 517 Note 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.515 Note that the definitions of ``\lstinline@&&@'' and ``\lstinline@||@'' say that they work by checking that their arguments are unequal to 0, so defining ``\lstinline@!=@'' and ``\lstinline@0@'' for user-defined types is enough to allow them to be used in logical expressions. 518 516 519 517 \item … … 524 522 \item 525 523 The ``address of'' operator. 526 It would seem useful to define a unary `` ©&©'' operator that returns values of some programmer-defined pointer-like type.524 It would seem useful to define a unary ``\lstinline@&@'' operator that returns values of some programmer-defined pointer-like type. 527 525 The problem lies with the type of the operator. 528 Consider the expression ``©p = &x©'', where ©x© is of type ©T© and ©p© has the programmer-defined type ©T_ptr©. 529 The expression might be treated as a call to the unary function ``©&?©''. 530 Now 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. 531 Hence the parameter must have type ©T *©. 532 But then the expression must be rewritten as ``©p = &?( &x )©'' 526 Consider the expression ``\lstinline@p = &x@'', where \lstinline@x@ is of type 527 \lstinline@T@ and \lstinline@p@ has the programmer-defined type \lstinline@T_ptr@. 528 The expression might be treated as a call to the unary function ``\lstinline@&?@''. 529 Now what is the type of the function's parameter? It can not be \lstinline@T@, because then \lstinline@x@ would be passed by value, and there is no way to create a useful pointer-like result from a value. 530 Hence the parameter must have type \lstinline@T *@. 531 But then the expression must be rewritten as ``\lstinline@p = &?( &x )@'' 533 532 ---which doesn't seem like progress! 534 533 535 534 The rule for address-of expressions would have to be something like ``keep applying address-of functions until you get one that takes a pointer argument, then use the built-in operator and stop''. 536 It seems simpler to define a conversion function from ©T *© to ©T_ptr©.537 538 \item 539 The ©sizeof©operator.535 It seems simpler to define a conversion function from \lstinline@T *@ to \lstinline@T_ptr@. 536 537 \item 538 The \lstinline@sizeof@ operator. 540 539 It is already defined for every object type, and intimately tied into the language's storage allocation model. 541 540 Redefining it seems pointless. 542 541 543 542 \item 544 The ``member of'' operators `` ©.©'' and ``©->©''.543 The ``member of'' operators ``\lstinline@.@'' and ``\lstinline@->@''. 545 544 These are not really infix operators, since their right ``operand'' is not a value or object. 546 545 … … 579 578 The ``fewest unsafe conversions'' rule ensures that the usual conversions are done, if possible. 580 579 The ``lowest total expression cost'' rule chooses the proper common type. 581 The odd-looking ``highest argument conversion cost'' rule ensures that, when unary expressions must be converted, conversions of function results are preferred to conversion of function arguments: ©(double)-i© will be preferred to ©-(double)i©.580 The odd-looking ``highest argument conversion cost'' rule ensures that, when unary expressions must be converted, conversions of function results are preferred to conversion of function arguments: \lstinline@(double)-i@ will be preferred to \lstinline@-(double)i@. 582 581 583 582 The ``least polymorphic'' rule reduces the number of polymorphic function calls, since such functions are presumably more expensive than monomorphic functions and since the more specific function is presumably more appropriate. 584 It also gives preference to monomorphic values (such as the ©int© ©0©) over polymorphic values (such as the \Index{null pointer} ©0©\use{0}). 583 It also gives preference to monomorphic values (such as the 584 \lstinline@int@ \lstinline@0@) over polymorphic values (such as the \Index{null pointer} 585 \lstinline@0@\use{0}). 585 586 However, interpretations that call polymorphic functions are preferred to interpretations that perform unsafe conversions, because those conversions potentially lose accuracy or violate strong typing. 586 587 … … 602 603 \begin{rationale} 603 604 Predefined functions and constants have internal linkage because that simplifies optimization in traditional compile-and-link environments. 604 For instance, `` ©an_int + an_int©'' is equivalent to ``©?+?(an_int, an_int)©''.605 For instance, ``\lstinline@an_int + an_int@'' is equivalent to ``\lstinline@?+?(an_int, an_int)@''. 605 606 If integer addition has not been redefined in the current scope, a compiler can generate code to perform the addition directly. 606 607 If predefined functions had external linkage, this optimization would be difficult. … … 628 629 \rhs \nonterm{constant} 629 630 \rhs \nonterm{string-literal} 630 \rhs ©(© \nonterm{expression} ©)©631 \rhs \lstinline@(@ \nonterm{expression} \lstinline@)@ 631 632 \rhs \nonterm{generic-selection} 632 633 \end{syntax} … … 644 645 645 646 A \nonterm{constant} or \nonterm{string-literal} has one valid interpretation, which has the type and value defined by {\c11}. 646 The predefined integer identifiers `` ©1©'' and ``©0©'' have the integer values 1 and 0, respectively.647 The 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.647 The predefined integer identifiers ``\lstinline@1@'' and ``\lstinline@0@'' have the integer values 1 and 0, respectively. 648 The other two predefined ``\lstinline@0@'' identifiers are bound to polymorphic pointer values that, when specialized\index{specialization} with a data type or function type respectively, produce a null pointer of that type. 648 649 649 650 A parenthesised expression has the same interpretations as the contained \nonterm{expression}. 650 651 651 652 \examples 652 The 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 *©. 653 In each case, the null pointer conversion is better\index{best valid interpretations} than the unsafe conversion of the integer ©0© to a pointer. 653 The expression \lstinline@(void *)0@\use{0} specializes the (polymorphic) null pointer to a null pointer to \lstinline@void@. \lstinline@(const void *)0@ does the same, and also uses a safe conversion from \lstinline@void *@ to \lstinline@const void *@. 654 In each case, the null pointer conversion is better\index{best valid interpretations} than the unsafe conversion of the integer 655 \lstinline@0@ to a pointer. 654 656 655 657 \begin{rationale} … … 657 659 658 660 \CFA does not have C's concept of ``null pointer constants'', which are not typed values but special strings of tokens. 659 The C token ``©0©'' is an expression of type ©int© with the value ``zero'', and it \emph{also} is a null pointer constant. 660 Similarly, ``©(void *)0© is an expression of type ©(void *)© whose value is a null pointer, and it also is a null pointer constant. 661 However, in C, ``©(void *)(void *)0©'' is 661 The C token ``\lstinline@0@'' is an expression of type \lstinline@int@ with the value ``zero'', and it \emph{also} is a null pointer constant. 662 Similarly, 663 ``\lstinline@(void *)0@ is an expression of type \lstinline@(void *)@ whose value is a null pointer, and it also is a null pointer constant. 664 However, in C, ``\lstinline@(void *)(void *)0@'' is 662 665 \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. 663 666 … … 666 669 \begin{lstlisting} 667 670 forall( dtype DT ) DT * const 0; 668 \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.671 \end{lstlisting} means that \lstinline@0@ is a polymorphic object, and contains a value that can have \emph{any} pointer-to-object type or pointer-to-incomplete type. 669 672 The only such value is the null pointer. 670 673 Therefore the type \emph{alone} is enough to identify a null pointer. … … 676 679 677 680 \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. 678 If 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.681 If a generic selection has no \lstinline@default@ generic association, the best interpretation of its controlling expression shall have type compatible with exactly one of the types named in its generic association list. 679 682 680 683 \semantics … … 687 690 \lhs{postfix-expression} 688 691 \rhs \nonterm{primary-expression} 689 \rhs \nonterm{postfix-expression} ©[© \nonterm{expression} ©]©690 \rhs \nonterm{postfix-expression} ©(©691 \nonterm{argument-expression-list}\opt ©)©692 \rhs \nonterm{postfix-expression} ©.©\nonterm{identifier}693 \rhs \nonterm{postfix-expression} ©->©\nonterm{identifier}694 \rhs \nonterm{postfix-expression} ©++©695 \rhs \nonterm{postfix-expression} ©--©696 \rhs ©(© \nonterm{type-name} ©)© ©{© \nonterm{initializer-list} ©}©697 \rhs ©(© \nonterm{type-name} ©)© ©{© \nonterm{initializer-list} ©,© ©}©692 \rhs \nonterm{postfix-expression} \lstinline@[@ \nonterm{expression} \lstinline@]@ 693 \rhs \nonterm{postfix-expression} \lstinline@(@ 694 \nonterm{argument-expression-list}\opt \lstinline@)@ 695 \rhs \nonterm{postfix-expression} \lstinline@.@ \nonterm{identifier} 696 \rhs \nonterm{postfix-expression} \lstinline@->@ \nonterm{identifier} 697 \rhs \nonterm{postfix-expression} \lstinline@++@ 698 \rhs \nonterm{postfix-expression} \lstinline@--@ 699 \rhs \lstinline@(@ \nonterm{type-name} \lstinline@)@ \lstinline@{@ \nonterm{initializer-list} \lstinline@}@ 700 \rhs \lstinline@(@ \nonterm{type-name} \lstinline@)@ \lstinline@{@ \nonterm{initializer-list} \lstinline@,@ \lstinline@}@ 698 701 \lhs{argument-expression-list} 699 702 \rhs \nonterm{assignment-expression} 700 \rhs \nonterm{argument-expression-list} ©,©703 \rhs \nonterm{argument-expression-list} \lstinline@,@ 701 704 \nonterm{assignment-expression} 702 705 \end{syntax} … … 704 707 \rewriterules 705 708 \begin{lstlisting} 706 a[b] =>?[?]( b, a ) // if a has integer type§\use{?[?]}§707 a[b] =>?[?]( a, b ) // otherwise708 a( §\emph{arguments}§ ) =>?()( a, §\emph{arguments}§ )§\use{?()}§709 a++ =>?++(&( a ))§\use{?++}§710 a-- =>?--(&( a ))§\use{?--}§709 a[b] §\rewrite§ ?[?]( b, a ) // if a has integer type§\use{?[?]}§ 710 a[b] §\rewrite§ ?[?]( a, b ) // otherwise 711 a( §\emph{arguments}§ ) §\rewrite§ ?()( a, §\emph{arguments}§ )§\use{?()}§ 712 a++ §\rewrite§ ?++(&( a ))§\use{?++}§ 713 a-- §\rewrite§ ?--(&( a ))§\use{?--}§ 711 714 \end{lstlisting} 712 715 … … 736 739 The interpretations of subscript expressions are the interpretations of the corresponding function call expressions. 737 740 \begin{rationale} 738 C 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 ©?[?]©. 741 C defines subscripting as pointer arithmetic in a way that makes \lstinline@a[i]@ and 742 \lstinline@i[a]@ equivalent. \CFA provides the equivalence through a rewrite rule to reduce the number of overloadings of \lstinline@?[?]@. 739 743 740 744 Subscript expressions are rewritten as function calls that pass the first parameter by value. 741 745 This is somewhat unfortunate, since array-like types tend to be large. 742 The alternative is to use the rewrite rule `` ©a[b] => ?[?](&(a), b)©''.743 However, C semantics forbid this approach: the ©a© in ``©a[b]©'' can be an arbitrary pointer value, which does not have an address.746 The alternative is to use the rewrite rule ``\lstinline@a[b]@ \rewrite \lstinline@?[?](&(a), b)@''. 747 However, C semantics forbid this approach: the \lstinline@a@ in ``\lstinline@a[b]@'' can be an arbitrary pointer value, which does not have an address. 744 748 745 749 The repetitive form of the predefined identifiers shows up a deficiency\index{deficiencies!pointers … … 756 760 \nonterm{postfix-expression} in a function call may have some interpretations that are function designators and some that are not. 757 761 758 For those interpretations of the \nonterm{postfix-expression} that are not function designators, the expression is rewritten and becomes a call of a function named `` ©?()©''.762 For those interpretations of the \nonterm{postfix-expression} that are not function designators, the expression is rewritten and becomes a call of a function named ``\lstinline@?()@''. 759 763 The valid interpretations of the rewritten expression are determined in the manner described below. 760 764 … … 763 767 \begin{itemize} 764 768 \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 765 \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. 769 \item if the function designator's type does not include a prototype or if the argument corresponds to 770 ``\lstinline@...@'' in a prototype, a \Index{default argument promotion} is applied to it. 766 771 \end{itemize} 767 772 The type of the valid interpretation is the return type of the function designator. 768 773 769 For 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 774 For those combinations where the interpretation of the \nonterm{postfix-expression} is a 775 \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 770 776 \begin{itemize} 771 777 \item 772 If the declaration of the implicit parameter uses \Index{type-class} ©type©\use{type}, the implicit argument must be an object type;773 if it uses ©dtype©, the implicit argument must be an object type or an incomplete type;774 and if it uses ©ftype©, the implicit argument must be a function type.778 If the declaration of the implicit parameter uses \Index{type-class} \lstinline@type@\use{type}, the implicit argument must be an object type; 779 if it uses \lstinline@dtype@, the implicit argument must be an object type or an incomplete type; 780 and if it uses \lstinline@ftype@, the implicit argument must be a function type. 775 781 776 782 \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. … … 791 797 \begin{rationale} 792 798 One desirable property of a polymorphic programming language is \define{generalizability}: the ability to replace an abstraction with a more general but equivalent abstraction without requiring changes in any of the uses of the original\cite{Cormack90}. 793 For 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©. 794 795 \CFA\index{deficiencies!generalizability} does not fully possess this property, because \Index{unsafe conversion} are not done when arguments are passed to polymorphic parameters. 799 For instance, it should be possible to replace a function ``\lstinline@int f( int );@'' with ``\lstinline@forall( otype T ) T f( T );@'' without affecting any calls of \lstinline@f@. 800 801 \CFA\index{deficiencies!generalizability} does not fully possess this property, because 802 \Index{unsafe conversion} are not done when arguments are passed to polymorphic parameters. 796 803 Consider 797 804 \begin{lstlisting} … … 804 811 f = g( d, f ); // (3) (unsafe conversion to float) 805 812 \end{lstlisting} 806 If ©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©. 807 808 Another example is the function ``©void h( int *);©''. 809 This function can be passed a ©void *© argument, but the generalization ``©forall( otype T ) void h( T *);©'' can not. 810 In this case, ©void© is not a valid value for ©T© because it is not an object type. 811 If unsafe conversions were allowed, ©T© could be inferred to be \emph{any} object type, which is undesirable. 813 If \lstinline@g@ was replaced by ``\lstinline@forall( otype T ) T g( T, T );@'', the first and second calls would be unaffected, but the third would change: \lstinline@f@ would be converted to 814 \lstinline@double@, and the result would be a \lstinline@double@. 815 816 Another example is the function ``\lstinline@void h( int *);@''. 817 This function can be passed a 818 \lstinline@void *@ argument, but the generalization ``\lstinline@forall( otype T ) void h( T *);@'' can not. 819 In this case, \lstinline@void@ is not a valid value for \lstinline@T@ because it is not an object type. 820 If unsafe conversions were allowed, \lstinline@T@ could be inferred to be \emph{any} object type, which is undesirable. 812 821 \end{rationale} 813 822 814 823 \examples 815 A function called `` ©?()©'' might be part of a numerical differentiation package.824 A function called ``\lstinline@?()@'' might be part of a numerical differentiation package. 816 825 \begin{lstlisting} 817 826 extern otype Derivative; … … 824 833 d = sin_dx( 12.9 ); 825 834 \end{lstlisting} 826 Here, the only interpretation of ©sin_dx© is as an object of type ©Derivative©.827 For that interpretation, the function call is treated as `` ©?()( sin_dx, 12.9 )©''.835 Here, the only interpretation of \lstinline@sin_dx@ is as an object of type \lstinline@Derivative@. 836 For that interpretation, the function call is treated as ``\lstinline@?()( sin_dx, 12.9 )@''. 828 837 \begin{lstlisting} 829 838 int f( long ); // (1) … … 832 841 int i = f( 5 ); // calls (1) 833 842 \end{lstlisting} 834 Function (1) provides a valid interpretation of `` ©f( 5 )©'', using an implicit ©int© to ©long©conversion.835 The 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.843 Function (1) provides a valid interpretation of ``\lstinline@f( 5 )@'', using an implicit \lstinline@int@ to \lstinline@long@ conversion. 844 The other functions do not, since the second requires two arguments, and since there is no implicit conversion from \lstinline@int@ to \lstinline@int *@ that could be used with the third function. 836 845 837 846 \begin{lstlisting} … … 839 848 double d = h( 1.5 ); 840 849 \end{lstlisting} 841 ``©1.5©'' is a ©double© constant, so ©T© is inferred to be ©double©, and the result of the function call is a ©double©. 850 ``\lstinline@1.5@'' is a \lstinline@double@ constant, so \lstinline@T@ is inferred to be 851 \lstinline@double@, and the result of the function call is a \lstinline@double@. 842 852 843 853 \begin{lstlisting} 844 854 forall( otype T, otype U ) void g( T, U ); // (4) 845 855 forall( otype T ) void g( T, T ); // (5) 846 forall( otype T ) void g( T, long ); // (6)856 forall( otype T ) void g( T, long ); // (6) 847 857 void g( long, long ); // (7) 848 858 double d; 849 859 int i; 850 860 int *p; 851 g( d, d ); // calls (5)852 g( d, i ); // calls (6)853 g( i, i ); // calls (7)854 g( i, p ); // calls (4)855 \end{lstlisting} 856 The 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).861 g( d, d ); // calls (5) 862 g( d, i ); // calls (6) 863 g( i, i ); // calls (7) 864 g( i, p ); // calls (4) 865 \end{lstlisting} 866 The first call has valid interpretations for all four versions of \lstinline@g@. (6) and (7) are discarded because they involve unsafe \lstinline@double@-to-\lstinline@long@ conversions. (5) is chosen because it is less polymorphic than (4). 857 867 858 868 For the second call, (7) is again discarded. 859 Of the remaining interpretations for (4), (5), and (6) (with ©i© converted to ©long©), (6) is chosen because it is the least polymorphic.869 Of the remaining interpretations for (4), (5), and (6) (with \lstinline@i@ converted to \lstinline@long@), (6) is chosen because it is the least polymorphic. 860 870 861 871 The third call has valid interpretations for all of the functions; … … 873 883 shuffle( 9, 10 ); 874 884 \end{lstlisting} 875 The 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©. 876 \begin{lstlisting} 877 extern void q( int ); // (8) 878 extern void q( void * ); // (9) 885 The only possibility for \lstinline@U@ is \lstinline@double@, because that is the type used in the only visible \lstinline@max@ function. 9 and 10 must be converted to \lstinline@double@, and 886 \lstinline@min@ must be specialized with \lstinline@T@ bound to \lstinline@double@. 887 \begin{lstlisting} 888 extern void q( int ); // (8) 889 extern void q( void * ); // (9) 879 890 extern void r(); 880 891 q( 0 ); 881 892 r( 0 ); 882 893 \end{lstlisting} 883 The ©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).884 The former is chosen because the ©int© ©0©is \Index{less polymorphic}.885 For the same reason, ©int© ©0© is passed to ©r()©, even though it has \emph{no} declared parameter types.894 The \lstinline@int 0@ could be passed to (8), or the \lstinline@(void *)@ \Index{specialization} of the null pointer\index{null pointer} \lstinline@0@\use{0} could be passed to (9). 895 The former is chosen because the \lstinline@int@ \lstinline@0@ is \Index{less polymorphic}. 896 For the same reason, \lstinline@int@ \lstinline@0@ is passed to \lstinline@r()@, even though it has \emph{no} declared parameter types. 886 897 887 898 888 899 \subsubsection{Structure and union members} 889 900 890 \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©. 891 If 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. 892 If 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. 901 \semantics In the member selection expression ``\lstinline@s@.\lstinline@m@'', there shall be at least one interpretation of \lstinline@s@ whose type is a structure type or union type containing a member named \lstinline@m@. 902 If two or more interpretations of \lstinline@s@ have members named 903 \lstinline@m@ with mutually compatible types, then the expression has an \Index{ambiguous interpretation} whose type is the composite type of the types of the members. 904 If an interpretation of \lstinline@s@ has a member \lstinline@m@ whose type is not compatible with any other 905 \lstinline@s@'s \lstinline@m@, then the expression has an interpretation with the member's type. 893 906 The expression has no other interpretations. 894 907 895 The expression `` ©p->m©'' has the same interpretations as the expression ``©(*p).m©''.908 The expression ``\lstinline@p->m@'' has the same interpretations as the expression ``\lstinline@(*p).m@''. 896 909 897 910 … … 988 1001 * ?--( _Atomic const restrict volatile T * _Atomic restrict volatile * ); 989 1002 \end{lstlisting} 990 For every extended integer type ©X©there exist1003 For every extended integer type \lstinline@X@ there exist 991 1004 % Don't use predefined: keep this out of prelude.cf. 992 1005 \begin{lstlisting} … … 994 1007 ?--( volatile X * ), ?--( _Atomic volatile X * ); 995 1008 \end{lstlisting} 996 For every complete enumerated type ©E©there exist1009 For every complete enumerated type \lstinline@E@ there exist 997 1010 % Don't use predefined: keep this out of prelude.cf. 998 1011 \begin{lstlisting} … … 1002 1015 1003 1016 \begin{rationale} 1004 Note 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.1017 Note that ``\lstinline@++@'' and ``\lstinline@--@'' are rewritten as function calls that are given a pointer to that operand. (This is true of all operators that modify an operand.) As Hamish Macdonald has pointed out, this forces the modified operand of such expressions to be an lvalue. 1005 1018 This partially enforces the C semantic rule that such operands must be \emph{modifiable} lvalues. 1006 1019 \end{rationale} … … 1008 1021 \begin{rationale} 1009 1022 In C, a semantic rule requires that pointer operands of increment and decrement be pointers to object types. 1010 Hence, ©void *©objects cannot be incremented.1011 In \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©.1023 Hence, \lstinline@void *@ objects cannot be incremented. 1024 In \CFA, the restriction follows from the use of a \lstinline@type@ parameter in the predefined function definitions, as opposed to \lstinline@dtype@, since only object types can be inferred arguments corresponding to the type parameter \lstinline@T@. 1012 1025 \end{rationale} 1013 1026 … … 1027 1040 \end{lstlisting} 1028 1041 \begin{sloppypar} 1029 Since ©&(vs)© has type ©volatile short int *©, the best valid interpretation of ©vs++© calls the ©?++© function with the ©volatile short *© parameter. 1030 ©s++© does the same, applying the safe conversion from ©short int *© to ©volatile short int *©. 1031 Note that there is no conversion that adds an ©_Atomic© qualifier, so the ©_Atomic volatile short int© overloading does not provide a valid interpretation. 1042 Since \lstinline@&(vs)@ has type \lstinline@volatile short int *@, the best valid interpretation of 1043 \lstinline@vs++@ calls the \lstinline@?++@ function with the \lstinline@volatile short *@ parameter. 1044 \lstinline@s++@ does the same, applying the safe conversion from \lstinline@short int *@ to \lstinline@volatile short int *@. 1045 Note that there is no conversion that adds an \lstinline@_Atomic@ qualifier, so the \lstinline@_Atomic volatile short int@ overloading does not provide a valid interpretation. 1032 1046 \end{sloppypar} 1033 1047 1034 There 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.1035 1036 The 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.1048 There is no safe conversion from \lstinline@const short int *@ to \lstinline@volatile short int *@, and no \lstinline@?++@ function that accepts a \lstinline@const *@ parameter, so \lstinline@cs++@ has no valid interpretations. 1049 1050 The best valid interpretation of \lstinline@as++@ calls the \lstinline@short ?++@ function with the \lstinline@_Atomic volatile short int *@ parameter, applying a safe conversion to add the \lstinline@volatile@ qualifier. 1037 1051 \begin{lstlisting} 1038 1052 char * const restrict volatile * restrict volatile pqpc; … … 1041 1055 ppc++; 1042 1056 \end{lstlisting} 1043 Since ©&(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 *©.1044 1045 ©ppc++© calls the same function, again inferring ©T© to be ©char *©, and using the safe conversions from ©T© to ©T const© ©restrict volatile©.1057 Since \lstinline@&(pqpc)@ has type \lstinline@char * const restrict volatile * restrict volatile *@, the best valid interpretation of \lstinline@pqpc++@ calls the polymorphic \lstinline@?++@ function with the \lstinline@const restrict volatile T * restrict volatile *@ parameter, inferring \lstinline@T@ to be \lstinline@char *@. 1058 1059 \lstinline@ppc++@ calls the same function, again inferring \lstinline@T@ to be \lstinline@char *@, and using the safe conversions from \lstinline@T@ to \lstinline@T const@ \lstinline@restrict volatile@. 1046 1060 1047 1061 \begin{rationale} … … 1057 1071 \begin{enumerate} 1058 1072 \item 1059 `` ©char * p; p++;©''.1060 The argument to ©?++© has type ©char * *©, and the result has type ©char *©.1061 The expression would be valid if ©?++©were declared by1073 ``\lstinline@char * p; p++;@''. 1074 The argument to \lstinline@?++@ has type \lstinline@char * *@, and the result has type \lstinline@char *@. 1075 The expression would be valid if \lstinline@?++@ were declared by 1062 1076 \begin{lstlisting} 1063 1077 forall( otype T ) T * ?++( T * * ); 1064 \end{lstlisting} with ©T© inferred to be ©char©.1065 1066 \item 1067 `` ©char *restrict volatile qp; qp++©''.1068 The 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.1078 \end{lstlisting} with \lstinline@T@ inferred to be \lstinline@char@. 1079 1080 \item 1081 ``\lstinline@char *restrict volatile qp; qp++@''. 1082 The result again has type \lstinline@char *@, but the argument now has type \lstinline@char *restrict volatile *@, so it cannot be passed to the hypothetical function declared in point 1. 1069 1083 Hence the actual predefined function is 1070 1084 \begin{lstlisting} 1071 1085 forall( otype T ) T * ?++( T * restrict volatile * ); 1072 \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.) 1073 1074 \item 1075 ``©char *_Atomic ap; ap++©''. 1076 The result again has type ©char *©, but no safe conversion adds an ©_Atomic© qualifier, so the function in point 2 is not applicable. 1077 A separate overloading of ©?++© is required. 1078 1079 \item 1080 ``©char const volatile * pq; pq++©''. 1081 Here the result has type ©char const volatile *©, so a new overloading is needed: 1086 \end{lstlisting} which also accepts a \lstinline@char * *@ argument, because of the safe conversions that add 1087 \lstinline@volatile@ and \lstinline@restrict@ qualifiers. (The parameter is not const-qualified, so constant pointers cannot be incremented.) 1088 1089 \item 1090 ``\lstinline@char *_Atomic ap; ap++@''. 1091 The result again has type \lstinline@char *@, but no safe conversion adds an \lstinline@_Atomic@ qualifier, so the function in point 2 is not applicable. 1092 A separate overloading of \lstinline@?++@ is required. 1093 1094 \item 1095 ``\lstinline@char const volatile * pq; pq++@''. 1096 Here the result has type 1097 \lstinline@char const volatile *@, so a new overloading is needed: 1082 1098 \begin{lstlisting} 1083 1099 forall( otype T ) T const volatile * ?++( T const volatile *restrict volatile * ); … … 1086 1102 1087 1103 \item 1088 `` ©float *restrict * prp; prp++©''.1089 The ©restrict© qualifier is handled just like ©const© and ©volatile©in the previous case:1104 ``\lstinline@float *restrict * prp; prp++@''. 1105 The \lstinline@restrict@ qualifier is handled just like \lstinline@const@ and \lstinline@volatile@ in the previous case: 1090 1106 \begin{lstlisting} 1091 1107 forall( otype T ) T restrict * ?++( T restrict *restrict volatile * ); 1092 \end{lstlisting} with ©T© inferred to be ©float *©.1093 This looks odd, because {\c11} 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.1108 \end{lstlisting} with \lstinline@T@ inferred to be \lstinline@float *@. 1109 This looks odd, because {\c11} contains a constraint that requires restrict-qualified types to be pointer-to-object types, and \lstinline@T@ is not syntactically a pointer type. \CFA loosens the constraint. 1094 1110 \end{enumerate} 1095 1111 \end{rationale} … … 1107 1123 \lhs{unary-expression} 1108 1124 \rhs \nonterm{postfix-expression} 1109 \rhs ©++©\nonterm{unary-expression}1110 \rhs ©--©\nonterm{unary-expression}1125 \rhs \lstinline@++@ \nonterm{unary-expression} 1126 \rhs \lstinline@--@ \nonterm{unary-expression} 1111 1127 \rhs \nonterm{unary-operator} \nonterm{cast-expression} 1112 \rhs ©sizeof©\nonterm{unary-expression}1113 \rhs ©sizeof© ©(© \nonterm{type-name} ©)©1114 \lhs{unary-operator} one of \rhs ©&© ©*© ©+© ©-© ©~© ©!©1128 \rhs \lstinline@sizeof@ \nonterm{unary-expression} 1129 \rhs \lstinline@sizeof@ \lstinline@(@ \nonterm{type-name} \lstinline@)@ 1130 \lhs{unary-operator} one of \rhs \lstinline@&@ \lstinline@*@ \lstinline@+@ \lstinline@-@ \lstinline@~@ \lstinline@!@ 1115 1131 \end{syntax} 1116 1132 1117 1133 \rewriterules 1118 1134 \begin{lstlisting} 1119 *a => *?( a )§\use{*?}§1120 +a => +?( a )§\use{+?}§1121 -a => -?( a )§\use{-?}§1122 ~a => ~?( a )§\use{~?}§1123 !a => !?( a )§\use{"!?}§1124 ++a => ++?(&( a ))§\use{++?}§1125 --a => --?(&( a ))§\use{--?}§1135 *a §\rewrite§ *?( a ) §\use{*?}§ 1136 +a §\rewrite§ +?( a ) §\use{+?}§ 1137 -a §\rewrite§ -?( a ) §\use{-?}§ 1138 ~a §\rewrite§ ~?( a ) §\use{~?}§ 1139 !a §\rewrite§ !?( a ) §\use{"!?}§ 1140 ++a §\rewrite§ ++?(&( a )) §\use{++?}§ 1141 --a §\rewrite§ --?(&( a )) §\use{--?}§ 1126 1142 \end{lstlisting} 1127 1143 … … 1219 1235 * --?( _Atomic const restrict volatile T * _Atomic restrict volatile * ); 1220 1236 \end{lstlisting} 1221 For every extended integer type ©X©there exist1237 For every extended integer type \lstinline@X@ there exist 1222 1238 % Don't use predefined: keep this out of prelude.cf. 1223 1239 \begin{lstlisting} … … 1227 1243 --?( _Atomic volatile X * ); 1228 1244 \end{lstlisting} 1229 For every complete enumerated type ©E©there exist1245 For every complete enumerated type \lstinline@E@ there exist 1230 1246 % Don't use predefined: keep this out of prelude.cf. 1231 1247 \begin{lstlisting} … … 1264 1280 1265 1281 \constraints 1266 The operand of the unary ``©&©'' operator shall have exactly one \Index{interpretation}\index{ambiguous interpretation}, which shall be unambiguous. 1282 The operand of the unary ``\lstinline@&@'' operator shall have exactly one 1283 \Index{interpretation}\index{ambiguous interpretation}, which shall be unambiguous. 1267 1284 1268 1285 \semantics 1269 The ``©&©'' expression has one interpretation which is of type ©T *©, where ©T© is the type of the operand. 1286 The ``\lstinline@&@'' expression has one interpretation which is of type \lstinline@T *@, where 1287 \lstinline@T@ is the type of the operand. 1270 1288 1271 1289 The interpretations of an indirection expression are the interpretations of the corresponding function call. … … 1296 1314 forall( ftype FT ) int !?( FT * ); 1297 1315 \end{lstlisting} 1298 For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int©there exist1316 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1299 1317 % Don't use predefined: keep this out of prelude.cf. 1300 1318 \begin{lstlisting} … … 1310 1328 long int li; 1311 1329 void eat_double( double );§\use{eat_double}§ 1312 eat_double(-li ); // =>eat_double( -?( li ) );1313 \end{lstlisting} 1314 The valid interpretations of `` ©-li©'' (assuming no extended integer types exist) are1330 eat_double(-li ); // §\rewrite§ eat_double( -?( li ) ); 1331 \end{lstlisting} 1332 The valid interpretations of ``\lstinline@-li@'' (assuming no extended integer types exist) are 1315 1333 \begin{center} 1316 1334 \begin{tabular}{llc} interpretation & result type & expression conversion cost \\ 1317 1335 \hline 1318 ©-?( (int)li )© & ©int©& (unsafe) \\1319 ©-?( (unsigned)li)© & ©unsigned int©& (unsafe) \\1320 ©-?( (long)li)© & ©long©& 0 \\1321 ©-?( (long unsigned int)li)© & ©long unsigned int©& 1 \\1322 ©-?( (long long int)li)© & ©long long int©& 2 \\1323 ©-?( (long long unsigned int)li)© & ©long long unsigned int©& 3 \\1324 ©-?( (float)li)© & ©float©& 4 \\1325 ©-?( (double)li)© & ©double©& 5 \\1326 ©-?( (long double)li)© & ©long double©& 6 \\1327 ©-?( (_Complex float)li)© & ©float©& (unsafe) \\1328 ©-?( (_Complex double)li)© & ©double©& (unsafe) \\1329 ©-?( (_Complex long double)li)© & ©long double©& (unsafe) \\1336 \lstinline@-?( (int)li )@ & \lstinline@int@ & (unsafe) \\ 1337 \lstinline@-?( (unsigned)li)@ & \lstinline@unsigned int@ & (unsafe) \\ 1338 \lstinline@-?( (long)li)@ & \lstinline@long@ & 0 \\ 1339 \lstinline@-?( (long unsigned int)li)@ & \lstinline@long unsigned int@ & 1 \\ 1340 \lstinline@-?( (long long int)li)@ & \lstinline@long long int@ & 2 \\ 1341 \lstinline@-?( (long long unsigned int)li)@ & \lstinline@long long unsigned int@& 3 \\ 1342 \lstinline@-?( (float)li)@ & \lstinline@float@ & 4 \\ 1343 \lstinline@-?( (double)li)@ & \lstinline@double@ & 5 \\ 1344 \lstinline@-?( (long double)li)@ & \lstinline@long double@ & 6 \\ 1345 \lstinline@-?( (_Complex float)li)@ & \lstinline@float@ & (unsafe) \\ 1346 \lstinline@-?( (_Complex double)li)@ & \lstinline@double@ & (unsafe) \\ 1347 \lstinline@-?( (_Complex long double)li)@ & \lstinline@long double@ & (unsafe) \\ 1330 1348 \end{tabular} 1331 1349 \end{center} 1332 The valid interpretations of the ©eat_double©call, with the cost of the argument conversion and the cost of the entire expression, are1350 The valid interpretations of the \lstinline@eat_double@ call, with the cost of the argument conversion and the cost of the entire expression, are 1333 1351 \begin{center} 1334 1352 \begin{tabular}{lcc} interpretation & argument cost & expression cost \\ 1335 1353 \hline 1336 ©eat_double( (double)-?( (int)li) )©& 7 & (unsafe) \\1337 ©eat_double( (double)-?( (unsigned)li) )©& 6 & (unsafe) \\1338 ©eat_double( (double)-?(li) )©& 5 & \(0+5=5\) \\1339 ©eat_double( (double)-?( (long unsigned int)li) )©& 4 & \(1+4=5\) \\1340 ©eat_double( (double)-?( (long long int)li) )©& 3 & \(2+3=5\) \\1341 ©eat_double( (double)-?( (long long unsigned int)li) )© & 2& \(3+2=5\) \\1342 ©eat_double( (double)-?( (float)li) )©& 1 & \(4+1=5\) \\1343 ©eat_double( (double)-?( (double)li) )©& 0 & \(5+0=5\) \\1344 ©eat_double( (double)-?( (long double)li) )©& (unsafe) & (unsafe) \\1345 ©eat_double( (double)-?( (_Complex float)li) )©& (unsafe) & (unsafe) \\1346 ©eat_double( (double)-?( (_Complex double)li) )©& (unsafe) & (unsafe) \\1347 ©eat_double( (double)-?( (_Complex long double)li) )©& (unsafe) & (unsafe) \\1354 \lstinline@eat_double( (double)-?( (int)li) )@ & 7 & (unsafe) \\ 1355 \lstinline@eat_double( (double)-?( (unsigned)li) )@ & 6 & (unsafe) \\ 1356 \lstinline@eat_double( (double)-?(li) )@ & 5 & \(0+5=5\) \\ 1357 \lstinline@eat_double( (double)-?( (long unsigned int)li) )@ & 4 & \(1+4=5\) \\ 1358 \lstinline@eat_double( (double)-?( (long long int)li) )@ & 3 & \(2+3=5\) \\ 1359 \lstinline@eat_double( (double)-?( (long long unsigned int)li) )@& 2 & \(3+2=5\) \\ 1360 \lstinline@eat_double( (double)-?( (float)li) )@ & 1 & \(4+1=5\) \\ 1361 \lstinline@eat_double( (double)-?( (double)li) )@ & 0 & \(5+0=5\) \\ 1362 \lstinline@eat_double( (double)-?( (long double)li) )@ & (unsafe) & (unsafe) \\ 1363 \lstinline@eat_double( (double)-?( (_Complex float)li) )@ & (unsafe) & (unsafe) \\ 1364 \lstinline@eat_double( (double)-?( (_Complex double)li) )@ & (unsafe) & (unsafe) \\ 1365 \lstinline@eat_double( (double)-?( (_Complex long double)li) )@ & (unsafe) & (unsafe) \\ 1348 1366 \end{tabular} 1349 1367 \end{center} 1350 Each has result type ©void©, so the best must be selected.1368 Each has result type \lstinline@void@, so the best must be selected. 1351 1369 The interpretations involving unsafe conversions are discarded. 1352 The remainder have equal expression conversion costs, so the ``highest argument conversion cost'' rule is invoked, and the chosen interpretation is ©eat_double( (double)-?(li) )©. 1370 The remainder have equal expression conversion costs, so the 1371 ``highest argument conversion cost'' rule is invoked, and the chosen interpretation is 1372 \lstinline@eat_double( (double)-?(li) )@. 1353 1373 1354 1374 … … 1356 1376 1357 1377 \constraints 1358 The operand of ©sizeof© or ©_Alignof© shall not be ©type©, ©dtype©, or ©ftype©.1359 1360 When 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©.1361 1362 When ©sizeof©is applied to an identifier declared by a \nonterm{type-declaration} or a1378 The operand of \lstinline@sizeof@ or \lstinline@_Alignof@ shall not be \lstinline@type@, \lstinline@dtype@, or \lstinline@ftype@. 1379 1380 When the \lstinline@sizeof@\use{sizeof} operator is applied to an expression, the expression shall have exactly one \Index{interpretation}\index{ambiguous interpretation}, which shall be unambiguous. \semantics A \lstinline@sizeof@ or \lstinline@_Alignof@ expression has one interpretation, of type \lstinline@size_t@. 1381 1382 When \lstinline@sizeof@ is applied to an identifier declared by a \nonterm{type-declaration} or a 1363 1383 \nonterm{type-parameter}, it yields the size in bytes of the type that implements the operand. 1364 1384 When the operand is an opaque type or an inferred type parameter\index{inferred parameter}, the expression is not a constant expression. 1365 1385 1366 When ©_Alignof©is applied to an identifier declared by a \nonterm{type-declaration} or a1386 When \lstinline@_Alignof@ is applied to an identifier declared by a \nonterm{type-declaration} or a 1367 1387 \nonterm{type-parameter}, it yields the alignment requirement of the type that implements the operand. 1368 1388 When the operand is an opaque type or an inferred type parameter\index{inferred parameter}, the expression is not a constant expression. … … 1378 1398 } 1379 1399 \end{lstlisting} 1380 ``©sizeof Rational©'', although not statically known, is fixed. 1381 Within ©f()©, ``©sizeof(T)©'' is fixed for each call of ©f()©, but may vary from call to call. 1400 ``\lstinline@sizeof Rational@'', although not statically known, is fixed. 1401 Within \lstinline@f()@, 1402 ``\lstinline@sizeof(T)@'' is fixed for each call of \lstinline@f()@, but may vary from call to call. 1382 1403 \end{rationale} 1383 1404 … … 1388 1409 \lhs{cast-expression} 1389 1410 \rhs \nonterm{unary-expression} 1390 \rhs ©(© \nonterm{type-name} ©)©\nonterm{cast-expression}1411 \rhs \lstinline@(@ \nonterm{type-name} \lstinline@)@ \nonterm{cast-expression} 1391 1412 \end{syntax} 1392 1413 1393 1414 \constraints 1394 The \nonterm{type-name} in a \nonterm{cast-expression} shall not be ©type©, ©dtype©, or ©ftype©. 1415 The \nonterm{type-name} in a \nonterm{cast-expression} shall not be \lstinline@type@, 1416 \lstinline@dtype@, or \lstinline@ftype@. 1395 1417 1396 1418 \semantics 1397 1419 1398 In a \Index{cast expression} `` ©(©\nonterm{type-name}©)e©'', if1399 \nonterm{type-name} is the type of an interpretation of ©e©, then that interpretation is the only interpretation of the cast expression;1400 otherwise, ©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.1420 In a \Index{cast expression} ``\lstinline@(@\nonterm{type-name}\lstinline@)e@'', if 1421 \nonterm{type-name} is the type of an interpretation of \lstinline@e@, then that interpretation is the only interpretation of the cast expression; 1422 otherwise, \lstinline@e@ shall have some interpretation that can be converted to \nonterm{type-name}, and the interpretation of the cast expression is the cast of the interpretation that can be converted at the lowest cost. 1401 1423 The cast expression's interpretation is ambiguous\index{ambiguous interpretation} if more than one interpretation can be converted at the lowest cost or if the selected interpretation is ambiguous. 1402 1424 … … 1411 1433 \lhs{multiplicative-expression} 1412 1434 \rhs \nonterm{cast-expression} 1413 \rhs \nonterm{multiplicative-expression} ©*©\nonterm{cast-expression}1414 \rhs \nonterm{multiplicative-expression} ©/©\nonterm{cast-expression}1415 \rhs \nonterm{multiplicative-expression} ©%©\nonterm{cast-expression}1435 \rhs \nonterm{multiplicative-expression} \lstinline@*@ \nonterm{cast-expression} 1436 \rhs \nonterm{multiplicative-expression} \lstinline@/@ \nonterm{cast-expression} 1437 \rhs \nonterm{multiplicative-expression} \lstinline@%@ \nonterm{cast-expression} 1416 1438 \end{syntax} 1417 1439 1418 1440 \rewriterules 1419 1441 \begin{lstlisting} 1420 a * b =>?*?( a, b )§\use{?*?}§1421 a / b =>?/?( a, b )§\use{?/?}§1422 a % b =>?%?( a, b )§\use{?%?}§1442 a * b §\rewrite§ ?*?( a, b )§\use{?*?}§ 1443 a / b §\rewrite§ ?/?( a, b )§\use{?/?}§ 1444 a % b §\rewrite§ ?%?( a, b )§\use{?%?}§ 1423 1445 \end{lstlisting} 1424 1446 … … 1447 1469 ?*?( _Complex long double, _Complex long double ), ?/?( _Complex long double, _Complex long double ); 1448 1470 \end{lstlisting} 1449 For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int©there exist1471 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1450 1472 % Don't use predefined: keep this out of prelude.cf. 1451 1473 \begin{lstlisting} … … 1454 1476 1455 1477 \begin{rationale} 1456 {\c11} 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. 1478 {\c11} does not include conversions from the \Index{real type}s to \Index{complex type}s in the 1479 \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. 1457 1480 \end{rationale} 1458 1481 … … 1467 1490 eat_double( li % i ); 1468 1491 \end{lstlisting} 1469 `` ©li % i©'' is rewritten as ``©?%?(li, i )©''.1470 The 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 ) are1492 ``\lstinline@li % i@'' is rewritten as ``\lstinline@?%?(li, i )@''. 1493 The valid interpretations of \lstinline@?%?(li, i )@, the cost\index{conversion cost} of converting their arguments, and the cost of converting the result to \lstinline@double@ (assuming no extended integer types are present ) are 1471 1494 \begin{center} 1472 1495 \begin{tabular}{lcc} interpretation & argument cost & result cost \\ 1473 \hline 1474 © ?%?( (int)li, i )©& (unsafe) & 6 \\1475 © ?%?( (unsigned)li,(unsigned)i )©& (unsafe) & 5 \\1476 © ?%?( li, (long)i )©& 1 & 4 \\1477 © ?%?( (long unsigned)li,(long unsigned)i )©& 3 & 3 \\1478 © ?%?( (long long)li,(long long)i )©& 5 & 2 \\1479 © ?%?( (long long unsigned)li, (long long unsigned)i )©& 7 & 1 \\1496 \hline 1497 \lstinline@ ?%?( (int)li, i )@ & (unsafe) & 6 \\ 1498 \lstinline@ ?%?( (unsigned)li,(unsigned)i )@ & (unsafe) & 5 \\ 1499 \lstinline@ ?%?( li, (long)i )@ & 1 & 4 \\ 1500 \lstinline@ ?%?( (long unsigned)li,(long unsigned)i )@ & 3 & 3 \\ 1501 \lstinline@ ?%?( (long long)li,(long long)i )@ & 5 & 2 \\ 1502 \lstinline@ ?%?( (long long unsigned)li, (long long unsigned)i )@ & 7 & 1 \\ 1480 1503 \end{tabular} 1481 1504 \end{center} 1482 The best interpretation of ©eat_double( li, i )© is ©eat_double( (double)?%?(li, (long)i ))©, which has no unsafe conversions and the lowest total cost. 1483 1484 \begin{rationale} 1485 {\c11} defines most arithmetic operations to apply an \Index{integer promotion} to any argument that belongs to a type that has an \Index{integer conversion rank} less than that of ©int©. 1486 If ©s© is a ©short int©, ``©s *s©'' does not have type ©short int©; 1487 it is treated as ``©( (int)s ) * ( (int)s )©'', and has type ©int©. \CFA matches that pattern; 1488 it does not predefine ``©short ?*?( short, short )©''. 1505 The best interpretation of \lstinline@eat_double( li, i )@ is 1506 \lstinline@eat_double( (double)?%?(li, (long)i ))@, which has no unsafe conversions and the lowest total cost. 1507 1508 \begin{rationale} 1509 {\c11} defines most arithmetic operations to apply an \Index{integer promotion} to any argument that belongs to a type that has an \Index{integer conversion rank} less than that of \lstinline@int@.If 1510 \lstinline@s@ is a \lstinline@short int@, ``\lstinline@s *s@'' does not have type \lstinline@short int@; 1511 it is treated as ``\lstinline@( (int)s ) * ( (int)s )@'', and has type \lstinline@int@. \CFA matches that pattern; 1512 it does not predefine ``\lstinline@short ?*?( short, short )@''. 1489 1513 1490 1514 These ``missing'' operators limit polymorphism. … … 1495 1519 square( s ); 1496 1520 \end{lstlisting} 1497 Since \CFA does not define a multiplication operator for ©short int©, ©square( s )© is treated as ©square( (int)s )©, and the result has type ©int©. 1521 Since \CFA does not define a multiplication operator for \lstinline@short int@, 1522 \lstinline@square( s )@ is treated as \lstinline@square( (int)s )@, and the result has type 1523 \lstinline@int@. 1498 1524 This is mildly surprising, but it follows the {\c11} operator pattern. 1499 1525 … … 1504 1530 product( sa, 5); 1505 1531 \end{lstlisting} 1506 This has no valid interpretations, because \CFA has no conversion from ``array of ©short int©'' to ``array of ©int©''. 1532 This has no valid interpretations, because \CFA has no conversion from ``array of 1533 \lstinline@short int@'' to ``array of \lstinline@int@''. 1507 1534 The alternatives in such situations include 1508 1535 \begin{itemize} 1509 1536 \item 1510 Defining monomorphic overloadings of ©product© for ©short© and the other ``small'' types. 1511 \item 1512 Defining ``©short ?*?( short, short )©'' within the scope containing the call to ©product©. 1513 \item 1514 Defining ©product© to take as an argument a conversion function from the ``small'' type to the operator's argument type. 1537 Defining monomorphic overloadings of \lstinline@product@ for \lstinline@short@ and the other 1538 ``small'' types. 1539 \item 1540 Defining ``\lstinline@short ?*?( short, short )@'' within the scope containing the call to 1541 \lstinline@product@. 1542 \item 1543 Defining \lstinline@product@ to take as an argument a conversion function from the ``small'' type to the operator's argument type. 1515 1544 \end{itemize} 1516 1545 \end{rationale} … … 1522 1551 \lhs{additive-expression} 1523 1552 \rhs \nonterm{multiplicative-expression} 1524 \rhs \nonterm{additive-expression} ©+©\nonterm{multiplicative-expression}1525 \rhs \nonterm{additive-expression} ©-©\nonterm{multiplicative-expression}1553 \rhs \nonterm{additive-expression} \lstinline@+@ \nonterm{multiplicative-expression} 1554 \rhs \nonterm{additive-expression} \lstinline@-@ \nonterm{multiplicative-expression} 1526 1555 \end{syntax} 1527 1556 1528 1557 \rewriterules 1529 1558 \begin{lstlisting} 1530 a + b =>?+?( a, b )§\use{?+?}§1531 a - b =>?-?( a, b )§\use{?-?}§1559 a + b §\rewrite§ ?+?( a, b )§\use{?+?}§ 1560 a - b §\rewrite§ ?-?( a, b )§\use{?-?}§ 1532 1561 \end{lstlisting} 1533 1562 … … 1582 1611 * ?-?( _Atomic const restrict volatile T *, _Atomic const restrict volatile T * ); 1583 1612 \end{lstlisting} 1584 For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int©there exist1613 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1585 1614 % Don't use predefined: keep this out of prelude.cf. 1586 1615 \begin{lstlisting} … … 1592 1621 1593 1622 \begin{rationale} 1594 ©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.1623 \lstinline@ptrdiff_t@ is an implementation-defined identifier defined in \lstinline@<stddef.h>@ that is synonymous with a signed integral type that is large enough to hold the difference between two pointers. 1595 1624 It seems reasonable to use it for pointer addition as well. (This is technically a difference between \CFA and C, which only specifies that pointer addition uses an \emph{integral} argument.) Hence it is also used for subscripting, which is defined in terms of pointer addition. 1596 The {\c11} 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.1625 The {\c11} standard uses \lstinline@size_t@ in several cases where a library function takes an argument that is used as a subscript, but \lstinline@size_t@ is unsuitable here because it is an unsigned type. 1597 1626 \end{rationale} 1598 1627 … … 1603 1632 \lhs{shift-expression} 1604 1633 \rhs \nonterm{additive-expression} 1605 \rhs \nonterm{shift-expression} ©<<©\nonterm{additive-expression}1606 \rhs \nonterm{shift-expression} ©>>©\nonterm{additive-expression}1634 \rhs \nonterm{shift-expression} \lstinline@<<@ \nonterm{additive-expression} 1635 \rhs \nonterm{shift-expression} \lstinline@>>@ \nonterm{additive-expression} 1607 1636 \end{syntax} 1608 1637 1609 \rewriterules 1610 \begin{lstlisting} 1611 a << b => ?<<?( a, b )§\use{?<<?}§1612 a >> b => ?>>?( a, b )§\use{?>>?}§1638 \rewriterules \use{?>>?}%use{?<<?} 1639 \begin{lstlisting} 1640 a << b §\rewrite§ ?<<?( a, b ) 1641 a >> b §\rewrite§ ?>>?( a, b ) 1613 1642 \end{lstlisting} 1614 1643 … … 1622 1651 long long unsigned int ?<<?( long long unsigned int, int ), ?>>?( long long unsigned int, int); 1623 1652 \end{lstlisting} 1624 For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int©there exist1653 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1625 1654 % Don't use predefined: keep this out of prelude.cf. 1626 1655 \begin{lstlisting} … … 1642 1671 \lhs{relational-expression} 1643 1672 \rhs \nonterm{shift-expression} 1644 \rhs \nonterm{relational-expression} ©< ©\nonterm{shift-expression}1645 \rhs \nonterm{relational-expression} ©> ©\nonterm{shift-expression}1646 \rhs \nonterm{relational-expression} ©<=©\nonterm{shift-expression}1647 \rhs \nonterm{relational-expression} ©>=©\nonterm{shift-expression}1673 \rhs \nonterm{relational-expression} \lstinline@< @ \nonterm{shift-expression} 1674 \rhs \nonterm{relational-expression} \lstinline@> @ \nonterm{shift-expression} 1675 \rhs \nonterm{relational-expression} \lstinline@<=@ \nonterm{shift-expression} 1676 \rhs \nonterm{relational-expression} \lstinline@>=@ \nonterm{shift-expression} 1648 1677 \end{syntax} 1649 1678 1650 \rewriterules 1651 \begin{lstlisting} 1652 a < b => ?<?( a, b )§\use{?<?}§1653 a > b => ?>?( a, b )§\use{?>?}§1654 a <= b => ?<=?( a, b )§\use{?<=?}§1655 a >= b => ?>=?( a, b )§\use{?>=?}§1679 \rewriterules\use{?>?}\use{?>=?}%use{?<?}%use{?<=?} 1680 \begin{lstlisting} 1681 a < b §\rewrite§ ?<?( a, b ) 1682 a > b §\rewrite§ ?>?( a, b ) 1683 a <= b §\rewrite§ ?<=?( a, b ) 1684 a >= b §\rewrite§ ?>=?( a, b ) 1656 1685 \end{lstlisting} 1657 1686 … … 1685 1714 ?>=?( _Atomic const restrict volatile DT *, _Atomic const restrict volatile DT * ); 1686 1715 \end{lstlisting} 1687 For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int©there exist1716 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1688 1717 % Don't use predefined: keep this out of prelude.cf. 1689 1718 \begin{lstlisting} … … 1703 1732 \lhs{equality-expression} 1704 1733 \rhs \nonterm{relational-expression} 1705 \rhs \nonterm{equality-expression} ©==©\nonterm{relational-expression}1706 \rhs \nonterm{equality-expression} ©!=©\nonterm{relational-expression}1734 \rhs \nonterm{equality-expression} \lstinline@==@ \nonterm{relational-expression} 1735 \rhs \nonterm{equality-expression} \lstinline@!=@ \nonterm{relational-expression} 1707 1736 \end{syntax} 1708 1737 1709 1738 \rewriterules 1710 1739 \begin{lstlisting} 1711 a == b =>?==?( a, b )§\use{?==?}§1712 a != b =>?!=?( a, b )§\use{?"!=?}§1740 a == b §\rewrite§ ?==?( a, b )§\use{?==?}§ 1741 a != b §\rewrite§ ?!=?( a, b )§\use{?"!=?}§ 1713 1742 \end{lstlisting} 1714 1743 … … 1763 1792 ?==?( forall( ftype FT2) FT2*, forall( ftype FT3) FT3 * ), ?!=?( forall( ftype FT2) FT2*, forall( ftype FT3) FT3 * ); 1764 1793 \end{lstlisting} 1765 For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int©there exist1794 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1766 1795 % Don't use predefined: keep this out of prelude.cf. 1767 1796 \begin{lstlisting} … … 1771 1800 1772 1801 \begin{rationale} 1773 The 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.1802 The polymorphic equality operations come in three styles: comparisons between pointers of compatible types, between pointers to \lstinline@void@ and pointers to object types or incomplete types, and between the \Index{null pointer} constant and pointers to any type. 1774 1803 In the last case, a special constraint rule for null pointer constant operands has been replaced by a consequence of the \CFA type system. 1775 1804 \end{rationale} … … 1792 1821 \lhs{AND-expression} 1793 1822 \rhs \nonterm{equality-expression} 1794 \rhs \nonterm{AND-expression} ©&©\nonterm{equality-expression}1823 \rhs \nonterm{AND-expression} \lstinline@&@ \nonterm{equality-expression} 1795 1824 \end{syntax} 1796 1825 1797 1826 \rewriterules 1798 1827 \begin{lstlisting} 1799 a & b =>?&?( a, b )§\use{?&?}§1828 a & b §\rewrite§ ?&?( a, b )§\use{?&?}§ 1800 1829 \end{lstlisting} 1801 1830 … … 1809 1838 long long unsigned int ?&?( long long unsigned int, long long unsigned int ); 1810 1839 \end{lstlisting} 1811 For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int©there exist1840 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1812 1841 % Don't use predefined: keep this out of prelude.cf. 1813 1842 \begin{lstlisting} … … 1824 1853 \lhs{exclusive-OR-expression} 1825 1854 \rhs \nonterm{AND-expression} 1826 \rhs \nonterm{exclusive-OR-expression} ©^©\nonterm{AND-expression}1855 \rhs \nonterm{exclusive-OR-expression} \lstinline@^@ \nonterm{AND-expression} 1827 1856 \end{syntax} 1828 1857 1829 1858 \rewriterules 1830 1859 \begin{lstlisting} 1831 a ^ b =>?^?( a, b )§\use{?^?}§1860 a ^ b §\rewrite§ ?^?( a, b )§\use{?^?}§ 1832 1861 \end{lstlisting} 1833 1862 … … 1841 1870 long long unsigned int ?^?( long long unsigned int, long long unsigned int ); 1842 1871 \end{lstlisting} 1843 For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int©there exist1872 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1844 1873 % Don't use predefined: keep this out of prelude.cf. 1845 1874 \begin{lstlisting} … … 1856 1885 \lhs{inclusive-OR-expression} 1857 1886 \rhs \nonterm{exclusive-OR-expression} 1858 \rhs \nonterm{inclusive-OR-expression} ©|©\nonterm{exclusive-OR-expression}1887 \rhs \nonterm{inclusive-OR-expression} \lstinline@|@ \nonterm{exclusive-OR-expression} 1859 1888 \end{syntax} 1860 1889 1861 \rewriterules 1862 \begin{lstlisting} 1863 a | b => ?|?( a, b )§\use{?"|?}§1890 \rewriterules\use{?"|?} 1891 \begin{lstlisting} 1892 a | b §\rewrite§ ?|?( a, b ) 1864 1893 \end{lstlisting} 1865 1894 … … 1873 1902 long long unsigned int ?|?( long long unsigned int, long long unsigned int ); 1874 1903 \end{lstlisting} 1875 For every extended integer type ©X© with \Index{integer conversion rank} greater than the rank of ©int©there exist1904 For every extended integer type \lstinline@X@ with \Index{integer conversion rank} greater than the rank of \lstinline@int@ there exist 1876 1905 % Don't use predefined: keep this out of prelude.cf. 1877 1906 \begin{lstlisting} … … 1888 1917 \lhs{logical-AND-expression} 1889 1918 \rhs \nonterm{inclusive-OR-expression} 1890 \rhs \nonterm{logical-AND-expression} ©&&©\nonterm{inclusive-OR-expression}1919 \rhs \nonterm{logical-AND-expression} \lstinline@&&@ \nonterm{inclusive-OR-expression} 1891 1920 \end{syntax} 1892 1921 1893 \semantics The operands of the expression ``©a && b©'' are treated as ``©(int)((a)!=0)©'' and ``©(int)((b)!=0)©'', which shall both be unambiguous. 1894 The expression has only one interpretation, which is of type ©int©. 1895 \begin{rationale} 1896 When 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. 1897 1898 A common C idiom omits comparisons to ©0© in the controlling expressions of loops and ©if© statements. 1899 For instance, the loop below iterates as long as ©rp© points at a ©Rational© value that is non-zero. 1922 \semantics The operands of the expression ``\lstinline@a && b@'' are treated as 1923 ``\lstinline@(int)((a)!=0)@'' and ``\lstinline@(int)((b)!=0)@'', which shall both be unambiguous. 1924 The expression has only one interpretation, which is of type \lstinline@int@. 1925 \begin{rationale} 1926 When the operands of a logical expression are values of built-in types, and ``\lstinline@!=@'' has not been redefined for those types, the compiler can optimize away the function calls. 1927 1928 A common C idiom omits comparisons to \lstinline@0@ in the controlling expressions of loops and 1929 \lstinline@if@ statements. 1930 For instance, the loop below iterates as long as \lstinline@rp@ points at a \lstinline@Rational@ value that is non-zero. 1900 1931 1901 1932 \begin{lstlisting} … … 1906 1937 while ( rp && *rp ) { ... } 1907 1938 \end{lstlisting} 1908 The logical expression calls the ©Rational© inequality operator, passing it ©*rp© and the ©Rational 0©, and getting a 1 or 0 as a result.1909 In contrast, {\CC} would apply a programmer-defined ©Rational©-to-©int© conversion to ©*rp©in the equivalent situation.1910 The 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.1939 The logical expression calls the \lstinline@Rational@ inequality operator, passing it \lstinline@*rp@ and the \lstinline@Rational 0@, and getting a 1 or 0 as a result. 1940 In contrast, {\CC} would apply a programmer-defined \lstinline@Rational@-to-\lstinline@int@ conversion to \lstinline@*rp@ in the equivalent situation. 1941 The conversion to \lstinline@int@ would produce a general integer value, which is unfortunate, and possibly dangerous if the conversion was not written with this situation in mind. 1911 1942 \end{rationale} 1912 1943 … … 1917 1948 \lhs{logical-OR-expression} 1918 1949 \rhs \nonterm{logical-AND-expression} 1919 \rhs \nonterm{logical-OR-expression} ©||©\nonterm{logical-AND-expression}1950 \rhs \nonterm{logical-OR-expression} \lstinline@||@ \nonterm{logical-AND-expression} 1920 1951 \end{syntax} 1921 1952 1922 1953 \semantics 1923 1954 1924 The operands of the expression `` ©a || b©'' are treated as ``©(int)((a)!=0)©'' and ``©(int)((b))!=0)©'', which shall both be unambiguous.1925 The expression has only one interpretation, which is of type ©int©.1955 The operands of the expression ``\lstinline@a || b@'' are treated as ``\lstinline@(int)((a)!=0)@'' and ``\lstinline@(int)((b))!=0)@'', which shall both be unambiguous. 1956 The expression has only one interpretation, which is of type \lstinline@int@. 1926 1957 1927 1958 … … 1931 1962 \lhs{conditional-expression} 1932 1963 \rhs \nonterm{logical-OR-expression} 1933 \rhs \nonterm{logical-OR-expression} ©?©\nonterm{expression}1934 ©:©\nonterm{conditional-expression}1964 \rhs \nonterm{logical-OR-expression} \lstinline@?@ \nonterm{expression} 1965 \lstinline@:@ \nonterm{conditional-expression} 1935 1966 \end{syntax} 1936 1967 1937 1968 \semantics 1938 In 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 to1969 In the conditional expression\use{?:} ``\lstinline@a?b:c@'', if the second and third operands both have an interpretation with \lstinline@void@ type, then the expression has an interpretation with type \lstinline@void@, equivalent to 1939 1970 \begin{lstlisting} 1940 1971 ( int)(( a)!=0) ? ( void)( b) : ( void)( c) 1941 1972 \end{lstlisting} 1942 1973 1943 If 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 as1974 If the second and third operands both have interpretations with non-\lstinline@void@ types, the expression is treated as if it were the call ``\lstinline@cond((a)!=0, b, c)@'', with \lstinline@cond@ declared as 1944 1975 \begin{lstlisting} 1945 1976 forall( otype T ) T cond( int, T, T ); … … 1993 2024 rand() ? i : l; 1994 2025 \end{lstlisting} 1995 The best interpretation infers the expression's type to be ©long© and applies the safe ©int©-to-©long© conversion to ©i©. 2026 The best interpretation infers the expression's type to be \lstinline@long@ and applies the safe 2027 \lstinline@int@-to-\lstinline@long@ conversion to \lstinline@i@. 1996 2028 1997 2029 \begin{lstlisting} … … 2000 2032 rand() ? cip : vip; 2001 2033 \end{lstlisting} 2002 The expression has type ©const volatile int *©, with safe conversions applied to the second and third operands to add ©volatile© and ©const©qualifiers, respectively.2034 The expression has type \lstinline@const volatile int *@, with safe conversions applied to the second and third operands to add \lstinline@volatile@ and \lstinline@const@ qualifiers, respectively. 2003 2035 2004 2036 \begin{lstlisting} 2005 2037 rand() ? cip : 0; 2006 2038 \end{lstlisting} 2007 The expression has type ©const int *©, with a specialization conversion applied to ©0©. 2039 The expression has type \lstinline@const int *@, with a specialization conversion applied to 2040 \lstinline@0@. 2008 2041 2009 2042 … … 2016 2049 \nonterm{assignment-expression} 2017 2050 \lhs{assignment-operator} one of 2018 \rhs ©=©\ \ ©*=©\ \ ©/=©\ \ ©%=©\ \ ©+=©\ \ ©-=©\ \ ©<<=©\ \ ©>>=©\ \ ©&=©\ \ ©^=©\ \ ©|=© 2051 \rhs \lstinline@=@\ \ \lstinline@*=@\ \ \lstinline@/=@\ \ \lstinline@%=@\ \ \lstinline@+=@\ \ \lstinline@-=@\ \ 2052 \lstinline@<<=@\ \ \lstinline@>>=@\ \ \lstinline@&=@\ \ \lstinline@^=@\ \ \lstinline@|=@ 2019 2053 \end{syntax} 2020 2054 2021 2055 \rewriterules 2022 Let `` ©<-©'' be any of the assignment operators.2056 Let ``\(\leftarrow\)'' be any of the assignment operators. 2023 2057 Then 2024 \use{?=?}\use{?*=?}\use{?/=?}\use{?%=?}\use{?+=?}\use{?-=?}\use{?>>=?}\use{?&=?}\use{?^=?}\use{?"|=?}%use{?<<=?} 2025 \begin{lstlisting} 2026 a <- b => ?<-?( &( a ), b ) 2058 \use{?=?}\use{?*=?}\use{?/=?}\use{?%=?}\use{?+=?}\use{?-=?} 2059 \use{?>>=?}\use{?&=?}\use{?^=?}\use{?"|=?}%use{?<<=?} 2060 \begin{lstlisting} 2061 a §$\leftarrow$§ b §\rewrite§ ?§$\leftarrow$§?( &( a ), b ) 2027 2062 \end{lstlisting} 2028 2063 2029 2064 \semantics 2030 2065 Each interpretation of the left operand of an assignment expression is considered separately. 2031 For 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.2066 For each interpretation that is a bit-field or is declared with the \lstinline@register@ storage class specifier, the expression has one valid interpretation, with the type of the left operand. 2032 2067 The right operand is cast to that type, and the assignment expression is ambiguous if either operand is. 2033 2068 For the remaining interpretations, the expression is rewritten, and the interpretations of the assignment expression are the interpretations of the corresponding function call. … … 2262 2297 \end{lstlisting} 2263 2298 \begin{rationale} 2264 The 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.2265 \end{rationale} 2266 2267 For every complete structure or union type ©S©there exist2299 The pattern of overloadings for simple assignment resembles that of pointer increment and decrement, except that the polymorphic pointer assignment functions declare a \lstinline@dtype@ parameter, instead of a \lstinline@type@ parameter, because the left operand may be a pointer to an incomplete type. 2300 \end{rationale} 2301 2302 For every complete structure or union type \lstinline@S@ there exist 2268 2303 % Don't use predefined: keep this out of prelude.cf. 2269 2304 \begin{lstlisting} … … 2271 2306 \end{lstlisting} 2272 2307 2273 For every extended integer type ©X©there exist2308 For every extended integer type \lstinline@X@ there exist 2274 2309 % Don't use predefined: keep this out of prelude.cf. 2275 2310 \begin{lstlisting} … … 2277 2312 \end{lstlisting} 2278 2313 2279 For every complete enumerated type ©E©there exist2314 For every complete enumerated type \lstinline@E@ there exist 2280 2315 % Don't use predefined: keep this out of prelude.cf. 2281 2316 \begin{lstlisting} … … 2283 2318 \end{lstlisting} 2284 2319 \begin{rationale} 2285 The right-hand argument is ©int© because enumeration constants have type ©int©.2320 The right-hand argument is \lstinline@int@ because enumeration constants have type \lstinline@int@. 2286 2321 \end{rationale} 2287 2322 … … 2544 2579 \end{lstlisting} 2545 2580 2546 For every extended integer type ©X©there exist2581 For every extended integer type \lstinline@X@ there exist 2547 2582 % Don't use predefined: keep this out of prelude.cf. 2548 2583 \begin{lstlisting} … … 2559 2594 \end{lstlisting} 2560 2595 2561 For every complete enumerated type ©E©there exist2596 For every complete enumerated type \lstinline@E@ there exist 2562 2597 % Don't use predefined: keep this out of prelude.cf. 2563 2598 \begin{lstlisting} … … 2580 2615 \lhs{expression} 2581 2616 \rhs \nonterm{assignment-expression} 2582 \rhs \nonterm{expression} ©,©\nonterm{assignment-expression}2617 \rhs \nonterm{expression} \lstinline@,@ \nonterm{assignment-expression} 2583 2618 \end{syntax} 2584 2619 2585 2620 \semantics 2586 In the comma expression ``©a, b©'', the first operand is interpreted as ``©( void )(a)©'', which shall be unambiguous\index{ambiguous interpretation}. 2621 In the comma expression ``\lstinline@a, b@'', the first operand is interpreted as 2622 ``\lstinline@( void )(a)@'', which shall be unambiguous\index{ambiguous interpretation}. 2587 2623 The interpretations of the expression are the interpretations of the second operand. 2588 2624 … … 2619 2655 { ... } 2620 2656 \end{lstlisting} 2621 Without the rule, ©Complex©would be a type in the first case, and a parameter name in the second.2657 Without the rule, \lstinline@Complex@ would be a type in the first case, and a parameter name in the second. 2622 2658 \end{rationale} 2623 2659 … … 2676 2712 \begin{syntax} 2677 2713 \lhs{forall-specifier} 2678 \rhs ©forall© ©(© \nonterm{type-parameter-list} ©)©2714 \rhs \lstinline@forall@ \lstinline@(@ \nonterm{type-parameter-list} \lstinline@)@ 2679 2715 \end{syntax} 2680 2716 … … 2688 2724 } mkPair( T, T ); // illegal 2689 2725 \end{lstlisting} 2690 If an instance of ©struct Pair©was declared later in the current scope, what would the members' type be?2726 If an instance of \lstinline@struct Pair@ was declared later in the current scope, what would the members' type be? 2691 2727 \end{rationale} 2692 2728 \end{comment} … … 2695 2731 The \nonterm{type-parameter-list}s and assertions of the \nonterm{forall-specifier}s declare type identifiers, function and object identifiers with \Index{no linkage}. 2696 2732 2697 If, in the declaration ``©T D©'', ©T© contains \nonterm{forall-specifier}s and ©D© has the form 2733 If, in the declaration ``\lstinline@T D@'', \lstinline@T@ contains \nonterm{forall-specifier}s and 2734 \lstinline@D@ has the form 2698 2735 \begin{lstlisting} 2699 2736 D( §\normalsize\nonterm{parameter-type-list}§ ) 2700 \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 2701 \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. 2737 \end{lstlisting} then a type identifier declared by one of the \nonterm{forall-specifier}s is an \define{inferred parameter} of the function declarator if and only if it is not an inferred parameter of a function declarator in \lstinline@D@, and it is used in the type of a parameter in the following 2738 \nonterm{type-parameter-list} or it and an inferred parameter are used as arguments of a 2739 \Index{specification} in one of the \nonterm{forall-specifier}s. 2702 2740 The identifiers declared by assertions that use an inferred parameter of a function declarator are \Index{assertion parameter}s of that function declarator. 2703 2741 … … 2710 2748 forall( otype T ) T * alloc( void );§\use{alloc}§ int *p = alloc(); 2711 2749 \end{lstlisting} 2712 Here ©alloc()© would receive ©int© as an inferred argument, and return an ©int *©. 2713 In 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. 2714 2715 With the current restriction, ©alloc()© must be given an argument that determines ©T©: 2750 Here \lstinline@alloc()@ would receive \lstinline@int@ as an inferred argument, and return an 2751 \lstinline@int *@. 2752 In general, if a call to \lstinline@alloc()@ is a subexpression of an expression involving polymorphic functions and overloaded identifiers, there could be considerable distance between the call and the subexpression that causes \lstinline@T@ to be bound. 2753 2754 With the current restriction, \lstinline@alloc()@ must be given an argument that determines 2755 \lstinline@T@: 2716 2756 \begin{lstlisting} 2717 2757 forall( otype T ) T * alloc( T initial_value );§\use{alloc}§ … … 2721 2761 2722 2762 If a function declarator is part of a function definition, its inferred parameters and assertion parameters have \Index{block scope}; 2723 otherwise, identifiers declared by assertions have a \define{declaration scope}, which terminates at the end of the \nonterm{declaration}. 2763 otherwise, identifiers declared by assertions have a 2764 \define{declaration scope}, which terminates at the end of the \nonterm{declaration}. 2724 2765 2725 2766 A function type that has at least one inferred parameter is a \define{polymorphic function} type. … … 2730 2771 Let $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. 2731 2772 Let $f'$ be $f$ with every occurrence of $f_i$ replaced by $g_i$, for all $i$. 2732 Then $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. 2773 Then $f$ and $g$ are 2774 \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. 2733 2775 2734 2776 \examples … … 2738 2780 forall( otype T ) T fT( T ); 2739 2781 \end{lstlisting} 2740 ©fi()© takes an ©int© and returns an ©int©. ©fT()© takes a ©T© and returns a ©T©, for any type ©T©. 2782 \lstinline@fi()@ takes an \lstinline@int@ and returns an \lstinline@int@. \lstinline@fT()@ takes a 2783 \lstinline@T@ and returns a \lstinline@T@, for any type \lstinline@T@. 2741 2784 \begin{lstlisting} 2742 2785 int (*pfi )( int ) = fi; 2743 2786 forall( otype T ) T (*pfT )( T ) = fT; 2744 2787 \end{lstlisting} 2745 ©pfi© and ©pfT© are pointers to functions. ©pfT©is not polymorphic, but the function it points at is.2788 \lstinline@pfi@ and \lstinline@pfT@ are pointers to functions. \lstinline@pfT@ is not polymorphic, but the function it points at is. 2746 2789 \begin{lstlisting} 2747 2790 int (*fvpfi( void ))( int ) { … … 2752 2795 } 2753 2796 \end{lstlisting} 2754 ©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.2797 \lstinline@fvpfi()@ and \lstinline@fvpfT()@ are functions taking no arguments and returning pointers to functions. \lstinline@fvpfT()@ is monomorphic, but the function that its return value points at is polymorphic. 2755 2798 \begin{lstlisting} 2756 2799 forall( otype T ) int ( *fTpfi( T ) )( int ); … … 2758 2801 forall( otype T, otype U ) U ( *fTpfU( T ) )( U ); 2759 2802 \end{lstlisting} 2760 ©fTpfi()© is a polymorphic function that returns a pointer to a monomorphic function taking an integer and returning an integer. 2761 It could return ©pfi©. ©fTpfT()© is subtle: it is a polymorphic function returning a \emph{monomorphic} function taking and returning 2762 ©T©, where ©T© is an inferred parameter of ©fTpfT()©. 2763 For 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. 2764 ©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 *©. 2803 \lstinline@fTpfi()@ is a polymorphic function that returns a pointer to a monomorphic function taking an integer and returning an integer. 2804 It could return \lstinline@pfi@. \lstinline@fTpfT()@ is subtle: it is a polymorphic function returning a \emph{monomorphic} function taking and returning 2805 \lstinline@T@, where \lstinline@T@ is an inferred parameter of \lstinline@fTpfT()@. 2806 For instance, in the expression ``\lstinline@fTpfT(17)@'', \lstinline@T@ is inferred to be \lstinline@int@, and the returned value would have type \lstinline@int ( * )( int )@. ``\lstinline@fTpfT(17)(13)@'' and 2807 ``\lstinline@fTpfT("yes")("no")@'' are legal, but ``\lstinline@fTpfT(17)("no")@'' is illegal. 2808 \lstinline@fTpfU()@ is polymorphic ( in type \lstinline@T@), and returns a pointer to a function that is polymorphic ( in type \lstinline@U@). ``\lstinline@f5(17)("no")@'' is a legal expression of type 2809 \lstinline@char *@. 2765 2810 \begin{lstlisting} 2766 2811 forall( otype T, otype U, otype V ) U * f( T *, U, V * const ); 2767 2812 forall( otype U, otype V, otype W ) U * g( V *, U, W * const ); 2768 2813 \end{lstlisting} 2769 The functions ©f()© and ©g()©have compatible types.2814 The functions \lstinline@f()@ and \lstinline@g()@ have compatible types. 2770 2815 Let \(f\) and \(g\) be their types; 2771 then \(f_1\) = ©T©, \(f_2\) = ©U©, \(f_3\) = ©V©, \(g_1\)2772 = ©V©, \(g_2\) = ©U©, and \(g_3\) = ©W©.2816 then \(f_1\) = \lstinline@T@, \(f_2\) = \lstinline@U@, \(f_3\) = \lstinline@V@, \(g_1\) 2817 = \lstinline@V@, \(g_2\) = \lstinline@U@, and \(g_3\) = \lstinline@W@. 2773 2818 Replacing every \(f_i\) by \(g_i\) in \(f\) gives 2774 2819 \begin{lstlisting} … … 2776 2821 \end{lstlisting} which has a return type and parameter list that is compatible with \(g\). 2777 2822 \begin{rationale} 2778 The 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.2823 The word ``\lstinline@type@'' in a forall specifier is redundant at the moment, but I want to leave room for inferred parameters of ordinary types in case parameterized types get added one day. 2779 2824 2780 2825 Even without parameterized types, I might try to allow … … 2802 2847 \subsection{Type qualifiers} 2803 2848 2804 \CFA defines a new type qualifier ©lvalue©\impl{lvalue}\index{lvalue}.2849 \CFA defines a new type qualifier \lstinline@lvalue@\impl{lvalue}\index{lvalue}. 2805 2850 \begin{syntax} 2806 2851 \oldlhs{type-qualifier} 2807 \rhs ©lvalue©2852 \rhs \lstinline@lvalue@ 2808 2853 \end{syntax} 2809 2854 … … 2813 2858 \semantics 2814 2859 An object's type may be a restrict-qualified type parameter. 2815 ©restrict©does not establish any special semantics in that case.2860 \lstinline@restrict@ does not establish any special semantics in that case. 2816 2861 2817 2862 \begin{rationale} … … 2819 2864 \end{rationale} 2820 2865 2821 ©lvalue© may be used to qualify the return type of a function type. 2822 Let ©T© be an unqualified version of a type; 2823 then the result of calling a function with return type ©lvalue T© is a \Index{modifiable lvalue} of type ©T©. 2824 ©const©\use{const} and ©volatile©\use{volatile} qualifiers may also be added to indicate that the function result is a constant or volatile lvalue. 2825 \begin{rationale} 2826 The ©const© and ©volatile© qualifiers can only be sensibly used to qualify the return type of a function if the ©lvalue© qualifier is also used. 2866 \lstinline@lvalue@ may be used to qualify the return type of a function type. 2867 Let \lstinline@T@ be an unqualified version of a type; 2868 then the result of calling a function with return type 2869 \lstinline@lvalue T@ is a \Index{modifiable lvalue} of type \lstinline@T@. 2870 \lstinline@const@\use{const} and \lstinline@volatile@\use{volatile} qualifiers may also be added to indicate that the function result is a constant or volatile lvalue. 2871 \begin{rationale} 2872 The \lstinline@const@ and \lstinline@volatile@ qualifiers can only be sensibly used to qualify the return type of a function if the \lstinline@lvalue@ qualifier is also used. 2827 2873 \end{rationale} 2828 2874 … … 2831 2877 2832 2878 \begin{rationale} 2833 ©lvalue© provides some of the functionality of {\CC}'s ``©T&©'' ( reference to object of type ©T©) type.2879 \lstinline@lvalue@ provides some of the functionality of {\CC}'s ``\lstinline@T&@'' ( reference to object of type \lstinline@T@) type. 2834 2880 Reference types have four uses in {\CC}. 2835 2881 \begin{itemize} … … 2838 2884 2839 2885 \item 2840 A reference can be used to define an alias for a complicated lvalue expression, as a way of getting some of the functionality of the Pascal ©with©statement.2886 A reference can be used to define an alias for a complicated lvalue expression, as a way of getting some of the functionality of the Pascal \lstinline@with@ statement. 2841 2887 The following {\CC} code gives an example. 2842 2888 \begin{lstlisting} … … 2851 2897 A reference parameter can be used to allow a function to modify an argument without forcing the caller to pass the address of the argument. 2852 2898 This is most useful for user-defined assignment operators. 2853 In {\CC}, plain assignment is done by a function called `` ©operator=©'', and the two expressions2899 In {\CC}, plain assignment is done by a function called ``\lstinline@operator=@'', and the two expressions 2854 2900 \begin{lstlisting} 2855 2901 a = b; 2856 2902 operator=( a, b ); 2857 2903 \end{lstlisting} are equivalent. 2858 If ©a© and ©b© are of type ©T©, then the first parameter of ©operator=© must have type ``©T&©''. 2859 It 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;©''. 2860 2861 In the case of user-defined operators, this could just as well be handled by using pointer types and by changing the rewrite rules so that ``©a = b;©'' is equivalent to ``©operator=(&( a), b )©''. 2862 Reference parameters of ``normal'' functions are Bad Things, because they remove a useful property of C function calls: an argument can only be modified by a function if it is preceded by ``©&©''. 2904 If \lstinline@a@ and \lstinline@b@ are of type \lstinline@T@, then the first parameter of \lstinline@operator=@ must have type ``\lstinline@T&@''. 2905 It cannot have type 2906 \lstinline@T@, because then assignment couldn't alter the variable, and it can't have type 2907 ``\lstinline@T *@'', because the assignment would have to be written ``\lstinline@&a = b;@''. 2908 2909 In the case of user-defined operators, this could just as well be handled by using pointer types and by changing the rewrite rules so that ``\lstinline@a = b;@'' is equivalent to 2910 ``\lstinline@operator=(&( a), b )@''. 2911 Reference parameters of ``normal'' functions are Bad Things, because they remove a useful property of C function calls: an argument can only be modified by a function if it is preceded by ``\lstinline@&@''. 2863 2912 2864 2913 \item 2865 2914 References to \Index{const-qualified} types can be used instead of value parameters. Given the 2866 {\CC} function call `` ©fiddle( a_thing )©'', where the type of ©a_thing©is2867 ©Thing©, the type of ©fiddle©could be either of2915 {\CC} function call ``\lstinline@fiddle( a_thing )@'', where the type of \lstinline@a_thing@ is 2916 \lstinline@Thing@, the type of \lstinline@fiddle@ could be either of 2868 2917 \begin{lstlisting} 2869 2918 void fiddle( Thing ); 2870 2919 void fiddle( const Thing & ); 2871 2920 \end{lstlisting} 2872 If the second form is used, then constructors and destructors are not invoked to create a temporary variable at the call site ( and it is bad style for the caller to make any assumptions about such things), and within ©fiddle©the parameter is subject to the usual problems caused by aliases.2873 The reference form might be chosen for efficiency's sake if ©Thing©s are too large or their constructors or destructors are too expensive.2921 If the second form is used, then constructors and destructors are not invoked to create a temporary variable at the call site ( and it is bad style for the caller to make any assumptions about such things), and within \lstinline@fiddle@ the parameter is subject to the usual problems caused by aliases. 2922 The reference form might be chosen for efficiency's sake if \lstinline@Thing@s are too large or their constructors or destructors are too expensive. 2874 2923 An implementation may switch between them without causing trouble for well-behaved clients. 2875 2924 This leaves the implementor to define ``too large'' and ``too expensive''. … … 2879 2928 void fiddle( const volatile Thing ); 2880 2929 \end{lstlisting} with call-by-reference. 2881 Since 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''.2930 Since it knows all about the size of \lstinline@Thing@s and the parameter passing mechanism, it should be able to come up with a better definition of ``too large'', and may be able to make a good guess at ``too expensive''. 2882 2931 \end{itemize} 2883 2932 … … 2899 2948 \begin{syntax} 2900 2949 \lhs{spec-definition} 2901 \rhs ©spec©\nonterm{identifier}2902 ©(© \nonterm{type-parameter-list} ©)©2903 ©{© \nonterm{spec-declaration-list}\opt ©}©2950 \rhs \lstinline@spec@ \nonterm{identifier} 2951 \lstinline@(@ \nonterm{type-parameter-list} \lstinline@)@ 2952 \lstinline@{@ \nonterm{spec-declaration-list}\opt \lstinline@}@ 2904 2953 \lhs{spec-declaration-list} 2905 \rhs \nonterm{spec-declaration} ©;©2906 \rhs \nonterm{spec-declaration-list} \nonterm{spec-declaration} ©;©2954 \rhs \nonterm{spec-declaration} \lstinline@;@ 2955 \rhs \nonterm{spec-declaration-list} \nonterm{spec-declaration} \lstinline@;@ 2907 2956 \lhs{spec-declaration} 2908 2957 \rhs \nonterm{specifier-qualifier-list} \nonterm{declarator-list} 2909 2958 \lhs{declarator-list} 2910 2959 \rhs \nonterm{declarator} 2911 \rhs \nonterm{declarator-list} ©,©\nonterm{declarator}2960 \rhs \nonterm{declarator-list} \lstinline@,@ \nonterm{declarator} 2912 2961 \end{syntax} 2913 2962 \begin{rationale} … … 2931 2980 \rhs \nonterm{assertion-list} \nonterm{assertion} 2932 2981 \lhs{assertion} 2933 \rhs ©|© \nonterm{identifier} ©(© \nonterm{type-name-list} ©)©2934 \rhs ©|©\nonterm{spec-declaration}2982 \rhs \lstinline@|@ \nonterm{identifier} \lstinline@(@ \nonterm{type-name-list} \lstinline@)@ 2983 \rhs \lstinline@|@ \nonterm{spec-declaration} 2935 2984 \lhs{type-name-list} 2936 2985 \rhs \nonterm{type-name} 2937 \rhs \nonterm{type-name-list} ©,©\nonterm{type-name}2986 \rhs \nonterm{type-name-list} \lstinline@,@ \nonterm{type-name} 2938 2987 \end{syntax} 2939 2988 … … 2942 2991 The \nonterm{type-name-list} shall contain one \nonterm{type-name} argument for each \nonterm{type-parameter} in that specification's \nonterm{spec-parameter-list}. 2943 2992 If the 2944 \nonterm{type-parameter} uses type-class ©type©\use{type}, the argument shall be the type name of an \Index{object type};2945 if it uses ©dtype©, the argument shall be the type name of an object type or an \Index{incomplete type};2946 and if it uses ©ftype©, the argument shall be the type name of a \Index{function type}.2993 \nonterm{type-parameter} uses type-class \lstinline@type@\use{type}, the argument shall be the type name of an \Index{object type}; 2994 if it uses \lstinline@dtype@, the argument shall be the type name of an object type or an \Index{incomplete type}; 2995 and if it uses \lstinline@ftype@, the argument shall be the type name of a \Index{function type}. 2947 2996 2948 2997 \semantics 2949 An \define{assertion} is a declaration of a collection of objects and functions, called \define{assertion parameters}. 2998 An \define{assertion} is a declaration of a collection of objects and functions, called 2999 \define{assertion parameters}. 2950 3000 2951 3001 The 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. … … 2973 3023 trait sum_list( otype List, otype Element | summable( Element ) | list_of( List, Element ) ) {}; 2974 3024 \end{lstlisting} 2975 ©sum_list©contains seven declarations, which describe a list whose elements can be added up.2976 The assertion `` ©|sum_list( i_list, int )©''\use{sum_list} produces the assertion parameters3025 \lstinline@sum_list@ contains seven declarations, which describe a list whose elements can be added up. 3026 The assertion ``\lstinline@|sum_list( i_list, int )@''\use{sum_list} produces the assertion parameters 2977 3027 \begin{lstlisting} 2978 3028 int ?+=?( int *, int ); … … 2991 3041 \lhs{type-parameter-list} 2992 3042 \rhs \nonterm{type-parameter} 2993 \rhs \nonterm{type-parameter-list} ©,©\nonterm{type-parameter}3043 \rhs \nonterm{type-parameter-list} \lstinline@,@ \nonterm{type-parameter} 2994 3044 \lhs{type-parameter} 2995 3045 \rhs \nonterm{type-class} \nonterm{identifier} \nonterm{assertion-list}\opt 2996 3046 \lhs{type-class} 2997 \rhs ©type©2998 \rhs ©dtype©2999 \rhs ©ftype©3047 \rhs \lstinline@type@ 3048 \rhs \lstinline@dtype@ 3049 \rhs \lstinline@ftype@ 3000 3050 \lhs{type-declaration} 3001 \rhs \nonterm{storage-class-specifier}\opt ©type©\nonterm{type-declarator-list} \verb|;|3051 \rhs \nonterm{storage-class-specifier}\opt \lstinline@type@ \nonterm{type-declarator-list} \verb|;| 3002 3052 \lhs{type-declarator-list} 3003 3053 \rhs \nonterm{type-declarator} 3004 \rhs \nonterm{type-declarator-list} ©,©\nonterm{type-declarator}3054 \rhs \nonterm{type-declarator-list} \lstinline@,@ \nonterm{type-declarator} 3005 3055 \lhs{type-declarator} 3006 \rhs \nonterm{identifier} \nonterm{assertion-list}\opt ©=©\nonterm{type-name}3056 \rhs \nonterm{identifier} \nonterm{assertion-list}\opt \lstinline@=@ \nonterm{type-name} 3007 3057 \rhs \nonterm{identifier} \nonterm{assertion-list}\opt 3008 3058 \end{syntax} … … 3015 3065 3016 3066 An identifier declared by a \nonterm{type-parameter} has \Index{no linkage}. 3017 Identifiers declared with type-class ©type©\use{type} are \Index{object type}s; 3018 those declared with type-class ©dtype©\use{dtype} are \Index{incomplete type}s; 3019 and those declared with type-class ©ftype©\use{ftype} are \Index{function type}s. 3067 Identifiers declared with type-class \lstinline@type@\use{type} are \Index{object type}s; 3068 those declared with type-class 3069 \lstinline@dtype@\use{dtype} are \Index{incomplete type}s; 3070 and those declared with type-class 3071 \lstinline@ftype@\use{ftype} are \Index{function type}s. 3020 3072 The identifier has \Index{block scope} that terminates at the end of the \nonterm{spec-declaration-list} or polymorphic function that contains the \nonterm{type-parameter}. 3021 3073 … … 3025 3077 Within the scope of the declaration, \Index{implicit conversion}s can be performed between the defined type and the implementation type, and between pointers to the defined type and pointers to the implementation type. 3026 3078 3027 A 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}. 3028 If 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). 3079 A type declaration without an \Index{initializer} and without a \Index{storage-class specifier} or with storage-class specifier \lstinline@static@\use{static} defines an \Index{incomplete type}. 3080 If a 3081 \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). 3029 3082 \begin{rationale} 3030 3083 Incomplete type declarations allow compact mutually-recursive types. … … 3043 3096 \end{rationale} 3044 3097 3045 A type declaration without an initializer and with \Index{storage-class specifier} ©extern©\use{extern} is an \define{opaque type declaration}. 3046 Opaque types are \Index{object type}s. 3098 A type declaration without an initializer and with \Index{storage-class specifier} 3099 \lstinline@extern@\use{extern} is an \define{opaque type declaration}. 3100 Opaque types are 3101 \Index{object type}s. 3047 3102 An opaque type is not a \nonterm{constant-expression}; 3048 neither is a structure or union that has a member whose type is not a \nonterm{constant-expression}. 3049 Every other\Index{object type} is a \nonterm{constant-expression}.3103 neither is a structure or union that has a member whose type is not a \nonterm{constant-expression}. Every other 3104 \Index{object type} is a \nonterm{constant-expression}. 3050 3105 Objects with static storage duration shall be declared with a type that is a \nonterm{constant-expression}. 3051 3106 \begin{rationale} … … 3057 3112 \end{rationale} 3058 3113 3059 An \Index{incomplete type} which is not a qualified version\index{qualified type} of a type is a value of \Index{type-class} ©dtype©. 3060 An object type\index{object types} which is not a qualified version of a type is a value of type-classes ©type© and ©dtype©. 3061 A \Index{function type} is a value of type-class ©ftype©. 3114 An \Index{incomplete type} which is not a qualified version\index{qualified type} of a type is a value of \Index{type-class} \lstinline@dtype@. 3115 An object type\index{object types} which is not a qualified version of a type is a value of type-classes \lstinline@type@ and \lstinline@dtype@. 3116 A 3117 \Index{function type} is a value of type-class \lstinline@ftype@. 3062 3118 \begin{rationale} 3063 3119 Syntactically, a type value is a \nonterm{type-name}, which is a declaration for an object which omits the identifier being declared. … … 3068 3124 3069 3125 Type qualifiers are a weak point of C's type system. 3070 Consider 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. 3126 Consider the standard library function 3127 \lstinline@strchr()@ which, given a string and a character, returns a pointer to the first occurrence of the character in the string. 3071 3128 \begin{lstlisting} 3072 3129 char *strchr( const char *s, int c ) {§\impl{strchr}§ … … 3077 3134 } 3078 3135 \end{lstlisting} 3079 The 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. 3080 Hence the body must perform a cast, and ( even worse) ©strchr()© provides a type-safe way to attempt to modify constant strings. 3081 What is needed is some way to say that ©s©'s type might contain qualifiers, and the result type has exactly the same qualifiers. 3136 The parameter \lstinline@s@ must be \lstinline@const char *@, because \lstinline@strchr()@ might be used to search a constant string, but the return type must be \lstinline@char *@, because the result might be used to modify a non-constant string. 3137 Hence the body must perform a cast, and ( even worse) 3138 \lstinline@strchr()@ provides a type-safe way to attempt to modify constant strings. 3139 What is needed is some way to say that \lstinline@s@'s type might contain qualifiers, and the result type has exactly the same qualifiers. 3082 3140 Polymorphic functions do not provide a fix for this deficiency\index{deficiencies!pointers to qualified types}, because type qualifiers are not part of type values. 3083 Instead, overloading can be used to define ©strchr()©for each combination of qualifiers.3141 Instead, overloading can be used to define \lstinline@strchr()@ for each combination of qualifiers. 3084 3142 \end{rationale} 3085 3143 … … 3105 3163 }; 3106 3164 \end{lstlisting} 3107 Without 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©. 3165 Without this restriction, \CFA might require ``module initialization'' code ( since 3166 \lstinline@Rational@ has external linkage, it must be created before any other translation unit instantiates it), and would force an ordering on the initialization of the translation unit that defines \lstinline@Huge@ and the translation that declares \lstinline@Rational@. 3108 3167 3109 3168 A benefit of the restriction is that it prevents the declaration in separate translation units of types that contain each other, which would be hard to prevent otherwise. … … 3111 3170 // File a.c: 3112 3171 extern type t1; 3113 type t2 = struct { t1 f1; ... } // illegal3172 type t2 = struct { t1 f1; ... } // illegal 3114 3173 // File b.c: 3115 3174 extern type t2; 3116 type t1 = struct { t2 f2; ... } // illegal3175 type t1 = struct { t2 f2; ... } // illegal 3117 3176 \end{lstlisting} 3118 3177 \end{rationale} … … 3122 3181 \nonterm{struct-declaration}, type declarations can not be structure members. 3123 3182 The form of 3124 \nonterm{type-declaration} forbids arrays of, pointers to, and functions returning ©type©.3183 \nonterm{type-declaration} forbids arrays of, pointers to, and functions returning \lstinline@type@. 3125 3184 Hence the syntax of \nonterm{type-specifier} does not have to be extended to allow type-valued expressions. 3126 3185 It also side-steps the problem of type-valued expressions producing different values in different declarations. … … 3137 3196 #include <stdlib.h> 3138 3197 T * new( otype T ) { return ( T * )malloc( sizeof( T) ); }; 3139 ...int * ip = new( int );3140 \end{lstlisting} 3141 This 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©;3198 §\ldots§ int * ip = new( int ); 3199 \end{lstlisting} 3200 This looks sensible, but \CFA's declaration-before-use rules mean that ``\lstinline@T@'' in the function body refers to the parameter, but the ``\lstinline@T@'' in the return type refers to the meaning of \lstinline@T@ in the scope that contains \lstinline@new@; 3142 3201 it could be undefined, or a type name, or a function or variable name. 3143 3202 Nothing good can result from such a situation. … … 3156 3215 f2( v2 ); 3157 3216 \end{lstlisting} 3158 ©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]©.3217 \lstinline@V1@ is passed by value, so \lstinline@f1()@'s assignment to \lstinline@a[0]@ does not modify v1. \lstinline@V2@ is converted to a pointer, so \lstinline@f2()@ modifies \lstinline@v2[0]@. 3159 3218 3160 3219 A translation unit containing the declarations … … 3162 3221 extern type Complex;§\use{Complex}§ // opaque type declaration 3163 3222 extern float abs( Complex );§\use{abs}§ 3164 \end{lstlisting} can contain declarations of complex numbers, which can be passed to ©abs©.3165 Some other translation unit must implement ©Complex© and ©abs©.3223 \end{lstlisting} can contain declarations of complex numbers, which can be passed to \lstinline@abs@. 3224 Some other translation unit must implement \lstinline@Complex@ and \lstinline@abs@. 3166 3225 That unit might contain the declarations 3167 3226 \begin{lstlisting} … … 3172 3231 } 3173 3232 \end{lstlisting} 3174 Note that ©c© is implicitly converted to a ©struct©so that its components can be retrieved.3233 Note that \lstinline@c@ is implicitly converted to a \lstinline@struct@ so that its components can be retrieved. 3175 3234 3176 3235 \begin{lstlisting} … … 3180 3239 } 3181 3240 \end{lstlisting} 3182 ©t1©must be cast to its implementation type to prevent infinite recursion.3241 \lstinline@t1@ must be cast to its implementation type to prevent infinite recursion. 3183 3242 3184 3243 \begin{rationale} 3185 3244 Within the scope of a type definition, an instance of the type can be viewed as having that type or as having the implementation type. 3186 In the ©Time_of_day©example, the difference is important.3245 In the \lstinline@Time_of_day@ example, the difference is important. 3187 3246 Different languages have treated the distinction between the abstraction and the implementation in different ways. 3188 3247 \begin{itemize} 3189 3248 \item 3190 3249 Inside a Clu cluster \cite{CLU}, the declaration of an instance states which view applies. 3191 Two primitives called ©up© and ©down©can be used to convert between the views.3250 Two primitives called \lstinline@up@ and \lstinline@down@ can be used to convert between the views. 3192 3251 \item 3193 3252 The Simula class \cite{SIMULA87} is essentially a record type. 3194 3253 Since the only operations on a record are member selection and assignment, which can not be overloaded, there is never any ambiguity as to whether the abstraction or the implementation view is being used. 3195 3254 In {\CC} 3196 \cite{C++}, operations on class instances include assignment and `` ©&©'', which can be overloaded.3255 \cite{C++}, operations on class instances include assignment and ``\lstinline@&@'', which can be overloaded. 3197 3256 A ``scope resolution'' operator can be used inside the class to specify whether the abstract or implementation version of the operation should be used. 3198 3257 \item … … 3207 3266 In this case, explicit conversions between the derived type and the old type can be used. 3208 3267 \end{itemize} 3209 \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©.3268 \CFA's rules are like Clu's, except that implicit conversions and conversion costs allow it to do away with most uses of \lstinline@up@ and \lstinline@down@. 3210 3269 \end{rationale} 3211 3270 … … 3213 3272 \subsubsection{Default functions and objects} 3214 3273 3215 A 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©. 3274 A declaration\index{type declaration} of a type identifier \lstinline@T@ with type-class 3275 \lstinline@type@ implicitly declares a \define{default assignment} function 3276 \lstinline@T ?=?( T *, T )@\use{?=?}, with the same \Index{scope} and \Index{linkage} as the identifier \lstinline@T@. 3216 3277 \begin{rationale} 3217 3278 Assignment is central to C's imperative programming style, and every existing C object type has assignment defined for it ( except for array types, which are treated as pointer types for purposes of assignment). 3218 3279 Without this rule, nearly every inferred type parameter would need an accompanying assignment assertion parameter. 3219 If a type parameter should not have an assignment operation, ©dtype© should be used. 3280 If a type parameter should not have an assignment operation, 3281 \lstinline@dtype@ should be used. 3220 3282 If a type should not have assignment defined, the user can define an assignment function that causes a run-time error, or provide an external declaration but no definition and thus cause a link-time error. 3221 3283 \end{rationale} 3222 3284 3223 A definition\index{type definition} of a type identifier ©T© with \Index{implementation type} ©I© and type-class ©type© implicitly defines a default assignment function. 3224 A 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. 3225 The default objects and functions have the same \Index{scope} and \Index{linkage} as the identifier ©T©. 3285 A definition\index{type definition} of a type identifier \lstinline@T@ with \Index{implementation type} \lstinline@I@ and type-class \lstinline@type@ implicitly defines a default assignment function. 3286 A definition\index{type definition} of a type identifier \lstinline@T@ with implementation type \lstinline@I@ and an assertion list implicitly defines \define{default function}s and 3287 \define{default object}s as declared by the assertion declarations. 3288 The default objects and functions have the same \Index{scope} and \Index{linkage} as the identifier \lstinline@T@. 3226 3289 Their values are determined as follows: 3227 3290 \begin{itemize} 3228 3291 \item 3229 If 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.3230 Otherwise the scope of the declaration of ©T©must contain a definition of the default object.3292 If at the definition of \lstinline@T@ there is visible a declaration of an object with the same name as the default object, and if the type of that object with all occurrence of \lstinline@I@ replaced by \lstinline@T@ is compatible with the type of the default object, then the default object is initialized with that object. 3293 Otherwise the scope of the declaration of \lstinline@T@ must contain a definition of the default object. 3231 3294 3232 3295 \item 3233 If 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.3234 3235 Otherwise, 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.3236 3237 Otherwise the scope of the declaration of ©T©must contain a definition of the default function.3296 If at the definition of \lstinline@T@ there is visible a declaration of a function with the same name as the default function, and if the type of that function with all occurrence of \lstinline@I@ replaced by \lstinline@T@ is compatible with the type of the default function, then the default function calls that function after converting its arguments and returns the converted result. 3297 3298 Otherwise, if \lstinline@I@ contains exactly one anonymous member\index{anonymous member} such that at the definition of \lstinline@T@ there is visible a declaration of a function with the same name as the default function, and the type of that function with all occurrences of the anonymous member's type in its parameter list replaced by \lstinline@T@ is compatible with the type of the default function, then the default function calls that function after converting its arguments and returns the result. 3299 3300 Otherwise the scope of the declaration of \lstinline@T@ must contain a definition of the default function. 3238 3301 \end{itemize} 3239 3302 \begin{rationale} … … 3241 3304 \end{rationale} 3242 3305 3243 A function or object with the same type and name as a default function or object that is declared within the scope of the definition of ©T©replaces the default function or object.3306 A function or object with the same type and name as a default function or object that is declared within the scope of the definition of \lstinline@T@ replaces the default function or object. 3244 3307 3245 3308 \examples … … 3251 3314 Pair b = { 1, 1 }; 3252 3315 \end{lstlisting} 3253 The definition of ©Pair© implicitly defines two objects ©a© and ©b©. 3254 ©Pair a© inherits its value from the ©struct impl a©. 3255 The definition of ©Pair b© is compulsory because there is no ©struct impl b© to construct a value from. 3316 The definition of \lstinline@Pair@ implicitly defines two objects \lstinline@a@ and \lstinline@b@. 3317 \lstinline@Pair a@ inherits its value from the \lstinline@struct impl a@. 3318 The definition of 3319 \lstinline@Pair b@ is compulsory because there is no \lstinline@struct impl b@ to construct a value from. 3256 3320 \begin{lstlisting} 3257 3321 trait ss( otype T ) { … … 3266 3330 Doodad clone( Doodad ) { ... } 3267 3331 \end{lstlisting} 3268 The definition of ©Doodad©implicitly defines three functions:3332 The definition of \lstinline@Doodad@ implicitly defines three functions: 3269 3333 \begin{lstlisting} 3270 3334 Doodad ?=?( Doodad *, Doodad ); … … 3272 3336 void munge( Doodad * ); 3273 3337 \end{lstlisting} 3274 The assignment function inherits ©struct doodad©'s assignment function because the types match when ©struct doodad© is replaced by ©Doodad© throughout. 3275 ©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. 3276 Hence the definition of ``©Doodad clone( Doodad )©'' is necessary. 3338 The assignment function inherits \lstinline@struct doodad@'s assignment function because the types match when \lstinline@struct doodad@ is replaced by \lstinline@Doodad@ throughout. 3339 \lstinline@munge()@ inherits \lstinline@Whatsit@'s \lstinline@munge()@ because the types match when 3340 \lstinline@Whatsit@ is replaced by \lstinline@Doodad@ in the parameter list. \lstinline@clone()@ does \emph{not} inherit \lstinline@Whatsit@'s \lstinline@clone()@: replacement in the parameter list yields ``\lstinline@Whatsit clone( Doodad )@'', which is not compatible with 3341 \lstinline@Doodad@'s \lstinline@clone()@'s type. 3342 Hence the definition of 3343 ``\lstinline@Doodad clone( Doodad )@'' is necessary. 3277 3344 3278 3345 Default functions and objects are subject to the normal scope rules. 3279 3346 \begin{lstlisting} 3280 otype T = ...;3281 T a_T = ...; // Default assignment used.3347 otype T = §\ldots§; 3348 T a_T = §\ldots§; // Default assignment used. 3282 3349 T ?=?( T *, T ); 3283 T a_T = ...; // Programmer-defined assignment called.3350 T a_T = §\ldots§; // Programmer-defined assignment called. 3284 3351 \end{lstlisting} 3285 3352 \begin{rationale} … … 3314 3381 \begin{syntax} 3315 3382 \oldlhs{labeled-statement} 3316 \rhs ©case©\nonterm{case-value-list} : \nonterm{statement}3383 \rhs \lstinline@case@ \nonterm{case-value-list} : \nonterm{statement} 3317 3384 \lhs{case-value-list} 3318 3385 \rhs \nonterm{case-value} 3319 \rhs \nonterm{case-value-list} ©,©\nonterm{case-value}3386 \rhs \nonterm{case-value-list} \lstinline@,@ \nonterm{case-value} 3320 3387 \lhs{case-value} 3321 3388 \rhs \nonterm{constant-expression} 3322 3389 \rhs \nonterm{subrange} 3323 3390 \lhs{subrange} 3324 \rhs \nonterm{constant-expression} ©~©\nonterm{constant-expression}3391 \rhs \nonterm{constant-expression} \lstinline@~@ \nonterm{constant-expression} 3325 3392 \end{syntax} 3326 3393 … … 3335 3402 case 1~4, 9~14, 27~32: 3336 3403 \end{lstlisting} 3337 The ©case© and ©default© clauses are restricted within the ©switch© and ©choose©statements, precluding Duff's device.3404 The \lstinline@case@ and \lstinline@default@ clauses are restricted within the \lstinline@switch@ and \lstinline@choose@ statements, precluding Duff's device. 3338 3405 3339 3406 3340 3407 \subsection{Expression and null statements} 3341 3408 3342 The expression in an expression statement is treated as being cast to ©void©.3409 The expression in an expression statement is treated as being cast to \lstinline@void@. 3343 3410 3344 3411 … … 3347 3414 \begin{syntax} 3348 3415 \oldlhs{selection-statement} 3349 \rhs ©choose© ©(© \nonterm{expression} ©)©\nonterm{statement}3416 \rhs \lstinline@choose@ \lstinline@(@ \nonterm{expression} \lstinline@)@ \nonterm{statement} 3350 3417 \end{syntax} 3351 3418 3352 The controlling expression ©E© in the ©switch© and ©choose©statement:3419 The controlling expression \lstinline@E@ in the \lstinline@switch@ and \lstinline@choose@ statement: 3353 3420 \begin{lstlisting} 3354 3421 switch ( E ) ... … … 3356 3423 \end{lstlisting} may have more than one interpretation, but it shall have only one interpretation with an integral type. 3357 3424 An \Index{integer promotion} is performed on the expression if necessary. 3358 The constant expressions in ©case©statements with the switch are converted to the promoted type.3425 The constant expressions in \lstinline@case@ statements with the switch are converted to the promoted type. 3359 3426 3360 3427 … … 3362 3429 \subsubsection[The choose statement]{The \lstinline@choose@ statement} 3363 3430 3364 The ©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.3365 The ©fallthru© statement is used to fall through to the next ©case© or ©default©labeled statement.3431 The \lstinline@choose@ statement is the same as the \lstinline@switch@ statement except control transfers to the end of the \lstinline@choose@ statement at a \lstinline@case@ or \lstinline@default@ labeled statement. 3432 The \lstinline@fallthru@ statement is used to fall through to the next \lstinline@case@ or \lstinline@default@ labeled statement. 3366 3433 The following have identical meaning: 3367 3434 \begin{flushleft} … … 3388 3455 \end{tabular} 3389 3456 \end{flushleft} 3390 The ©choose© statement addresses the problem of accidental fall-through associated with the ©switch©statement.3457 The \lstinline@choose@ statement addresses the problem of accidental fall-through associated with the \lstinline@switch@ statement. 3391 3458 3392 3459 3393 3460 \subsection{Iteration statements} 3394 3461 3395 The controlling expression ©E©in the loops3462 The controlling expression \lstinline@E@ in the loops 3396 3463 \begin{lstlisting} 3397 3464 if ( E ) ... 3398 3465 while ( E ) ... 3399 3466 do ... while ( E ); 3400 \end{lstlisting} 3401 is treated as ``©( int )((E)!=0)©''. 3467 \end{lstlisting} is treated as ``\lstinline@( int )((E)!=0)@''. 3402 3468 3403 3469 The statement 3404 3470 \begin{lstlisting} 3405 for ( a; b; c ) ...3471 for ( a; b; c ) §\ldots§ 3406 3472 \end{lstlisting} is treated as 3407 3473 \begin{lstlisting} … … 3414 3480 \begin{syntax} 3415 3481 \oldlhs{jump-statement} 3416 \rhs ©continue©\nonterm{identifier}\opt3417 \rhs ©break©\nonterm{identifier}\opt3482 \rhs \lstinline@continue@ \nonterm{identifier}\opt 3483 \rhs \lstinline@break@ \nonterm{identifier}\opt 3418 3484 \rhs \ldots 3419 \rhs ©throw©\nonterm{assignment-expression}\opt3420 \rhs ©throwResume©\nonterm{assignment-expression}\opt \nonterm{at-expression}\opt3421 \lhs{at-expression} ©_At©\nonterm{assignment-expression}3485 \rhs \lstinline@throw@ \nonterm{assignment-expression}\opt 3486 \rhs \lstinline@throwResume@ \nonterm{assignment-expression}\opt \nonterm{at-expression}\opt 3487 \lhs{at-expression} \lstinline@_At@ \nonterm{assignment-expression} 3422 3488 \end{syntax} 3423 3489 3424 Labeled ©continue© and ©break© allow useful but restricted control-flow that reduces the need for the ©goto©statement for exiting multiple nested control-structures.3490 Labeled \lstinline@continue@ and \lstinline@break@ allow useful but restricted control-flow that reduces the need for the \lstinline@goto@ statement for exiting multiple nested control-structures. 3425 3491 \begin{lstlisting} 3426 3492 L1: { // compound … … 3451 3517 \subsubsection[The continue statement]{The \lstinline@continue@ statement} 3452 3518 3453 The identifier in a ©continue©statement shall name a label located on an enclosing iteration statement.3519 The identifier in a \lstinline@continue@ statement shall name a label located on an enclosing iteration statement. 3454 3520 3455 3521 3456 3522 \subsubsection[The break statement]{The \lstinline@break@ statement} 3457 3523 3458 The identifier in a ©break©statement shall name a label located on an enclosing compound, selection or iteration statement.3524 The identifier in a \lstinline@break@ statement shall name a label located on an enclosing compound, selection or iteration statement. 3459 3525 3460 3526 3461 3527 \subsubsection[The return statement]{The \lstinline@return@ statement} 3462 3528 3463 An expression in a ©return©statement is treated as being cast to the result type of the function.3529 An expression in a \lstinline@return@ statement is treated as being cast to the result type of the function. 3464 3530 3465 3531 … … 3476 3542 \begin{syntax} 3477 3543 \lhs{exception-statement} 3478 \rhs ©try©\nonterm{compound-statement} \nonterm{handler-list}3479 \rhs ©try©\nonterm{compound-statement} \nonterm{finally-clause}3480 \rhs ©try©\nonterm{compound-statement} \nonterm{handler-list} \nonterm{finally-clause}3544 \rhs \lstinline@try@ \nonterm{compound-statement} \nonterm{handler-list} 3545 \rhs \lstinline@try@ \nonterm{compound-statement} \nonterm{finally-clause} 3546 \rhs \lstinline@try@ \nonterm{compound-statement} \nonterm{handler-list} \nonterm{finally-clause} 3481 3547 \lhs{handler-list} 3482 3548 \rhs \nonterm{handler-clause} 3483 \rhs ©catch© ©(© \ldots ©)©\nonterm{compound-statement}3484 \rhs \nonterm{handler-clause} ©catch© ©(© \ldots ©)©\nonterm{compound-statement}3485 \rhs ©catchResume© ©(© \ldots ©)©\nonterm{compound-statement}3486 \rhs \nonterm{handler-clause} ©catchResume© ©(© \ldots ©)©\nonterm{compound-statement}3549 \rhs \lstinline@catch@ \lstinline@(@ \ldots \lstinline@)@ \nonterm{compound-statement} 3550 \rhs \nonterm{handler-clause} \lstinline@catch@ \lstinline@(@ \ldots \lstinline@)@ \nonterm{compound-statement} 3551 \rhs \lstinline@catchResume@ \lstinline@(@ \ldots \lstinline@)@ \nonterm{compound-statement} 3552 \rhs \nonterm{handler-clause} \lstinline@catchResume@ \lstinline@(@ \ldots \lstinline@)@ \nonterm{compound-statement} 3487 3553 \lhs{handler-clause} 3488 \rhs ©catch© ©(© \nonterm{exception-declaration} ©)©\nonterm{compound-statement}3489 \rhs \nonterm{handler-clause} ©catch© ©(© \nonterm{exception-declaration} ©)©\nonterm{compound-statement}3490 \rhs ©catchResume© ©(© \nonterm{exception-declaration} ©)©\nonterm{compound-statement}3491 \rhs \nonterm{handler-clause} ©catchResume© ©(© \nonterm{exception-declaration} ©)©\nonterm{compound-statement}3554 \rhs \lstinline@catch@ \lstinline@(@ \nonterm{exception-declaration} \lstinline@)@ \nonterm{compound-statement} 3555 \rhs \nonterm{handler-clause} \lstinline@catch@ \lstinline@(@ \nonterm{exception-declaration} \lstinline@)@ \nonterm{compound-statement} 3556 \rhs \lstinline@catchResume@ \lstinline@(@ \nonterm{exception-declaration} \lstinline@)@ \nonterm{compound-statement} 3557 \rhs \nonterm{handler-clause} \lstinline@catchResume@ \lstinline@(@ \nonterm{exception-declaration} \lstinline@)@ \nonterm{compound-statement} 3492 3558 \lhs{finally-clause} 3493 \rhs ©finally©\nonterm{compound-statement}3559 \rhs \lstinline@finally@ \nonterm{compound-statement} 3494 3560 \lhs{exception-declaration} 3495 3561 \rhs \nonterm{type-specifier} … … 3499 3565 \rhs \nonterm{new-abstract-declarator-tuple} 3500 3566 \lhs{asynchronous-statement} 3501 \rhs ©enable©\nonterm{identifier-list} \nonterm{compound-statement}3502 \rhs ©disable©\nonterm{identifier-list} \nonterm{compound-statement}3567 \rhs \lstinline@enable@ \nonterm{identifier-list} \nonterm{compound-statement} 3568 \rhs \lstinline@disable@ \nonterm{identifier-list} \nonterm{compound-statement} 3503 3569 \end{syntax} 3504 3570 … … 3508 3574 \subsubsection[The try statement]{The \lstinline@try@ statement} 3509 3575 3510 The ©try©statement is a block with associated handlers, called a \Index{guarded block};3576 The \lstinline@try@ statement is a block with associated handlers, called a \Index{guarded block}; 3511 3577 all other blocks are \Index{unguarded block}s. 3512 A ©goto©, ©break©, ©return©, or ©continue©statement can be used to transfer control out of a try block or handler, but not into one.3578 A \lstinline@goto@, \lstinline@break@, \lstinline@return@, or \lstinline@continue@ statement can be used to transfer control out of a try block or handler, but not into one. 3513 3579 3514 3580 3515 3581 \subsubsection[The enable/disable statements]{The \lstinline@enable@/\lstinline@disable@ statements} 3516 3582 3517 The ©enable©/©disable©statements toggle delivery of \Index{asynchronous exception}s.3583 The \lstinline@enable@/\lstinline@disable@ statements toggle delivery of \Index{asynchronous exception}s. 3518 3584 3519 3585 … … 3525 3591 \subsection{Predefined macro names} 3526 3592 3527 The implementation shall define the macro names ©__LINE__©, ©__FILE__©, ©__DATE__©, and ©__TIME__©, as in the {\c11} standard. 3528 It shall not define the macro name ©__STDC__©. 3529 3530 In addition, the implementation shall define the macro name ©__CFORALL__© to be the decimal constant 1. 3593 The implementation shall define the macro names \lstinline@__LINE__@, \lstinline@__FILE__@, 3594 \lstinline@__DATE__@, and \lstinline@__TIME__@, as in the {\c11} standard. 3595 It shall not define the macro name \lstinline@__STDC__@. 3596 3597 In addition, the implementation shall define the macro name \lstinline@__CFORALL__@ to be the decimal constant 1. 3531 3598 3532 3599 … … 3545 3612 The pointer, integral, and floating-point types are all \define{scalar types}. 3546 3613 All of these types can be logically negated and compared. 3547 The assertion `` ©scalar( Complex )©'' should be read as ``type ©Complex©is scalar''.3614 The assertion ``\lstinline@scalar( Complex )@'' should be read as ``type \lstinline@Complex@ is scalar''. 3548 3615 \begin{lstlisting} 3549 3616 trait scalar( otype T ) {§\impl{scalar}§ … … 3563 3630 \end{lstlisting} 3564 3631 3565 The various flavors of ©char© and ©int© and the enumerated types make up the \define{integral types}. 3632 The various flavors of \lstinline@char@ and \lstinline@int@ and the enumerated types make up the 3633 \define{integral types}. 3566 3634 \begin{lstlisting} 3567 3635 trait integral( otype T | arithmetic( T ) ) {§\impl{integral}§§\use{arithmetic}§ … … 3596 3664 3597 3665 Modifiable arithmetic lvalues are both modifiable scalar lvalues and arithmetic. 3598 Note that this results in the ``inheritance'' of ©scalar©along both paths.3666 Note that this results in the ``inheritance'' of \lstinline@scalar@ along both paths. 3599 3667 \begin{lstlisting} 3600 3668 trait m_l_arithmetic( otype T | m_l_scalar( T ) | arithmetic( T ) ) {§\impl{m_l_arithmetic}§ … … 3611 3679 \subsection{Pointer and array types} 3612 3680 3613 Array types can barely be said to exist in {\c11}, since in most cases an array name is treated as a constant pointer to the first element of the array, and the subscript expression ``©a[i]©'' is equivalent to the dereferencing expression ``©(*( a+( i )))©''. 3614 Technically, 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. 3681 Array types can barely be said to exist in {\c11}, since in most cases an array name is treated as a constant pointer to the first element of the array, and the subscript expression 3682 ``\lstinline@a[i]@'' is equivalent to the dereferencing expression ``\lstinline@(*( a+( i )))@''. 3683 Technically, pointer arithmetic and pointer comparisons other than ``\lstinline@==@'' and 3684 ``\lstinline@!=@'' are only defined for pointers to array elements, but the type system does not enforce those restrictions. 3615 3685 Consequently, there is no need for a separate ``array type'' specification. 3616 3686 3617 3687 Pointer types are scalar types. 3618 Like 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©. 3688 Like other scalar types, they have ``\lstinline@+@'' and 3689 ``\lstinline@-@'' operators, but the types do not match the types of the operations in 3690 \lstinline@arithmetic@, so these operators cannot be consolidated in \lstinline@scalar@. 3619 3691 \begin{lstlisting} 3620 3692 trait pointer( type P | scalar( P ) ) {§\impl{pointer}§§\use{scalar}§ … … 3631 3703 Specifications that define the dereference operator ( or subscript operator ) require two parameters, one for the pointer type and one for the pointed-at ( or element ) type. 3632 3704 Different specifications are needed for each set of \Index{type qualifier}s, because qualifiers are not included in types. 3633 The assertion ``©|ptr_to( Safe_pointer, int )©'' should be read as ``©Safe_pointer© acts like a pointer to ©int©''. 3705 The assertion ``\lstinline@|ptr_to( Safe_pointer, int )@'' should be read as 3706 ``\lstinline@Safe_pointer@ acts like a pointer to \lstinline@int@''. 3634 3707 \begin{lstlisting} 3635 3708 trait ptr_to( otype P | pointer( P ), otype T ) {§\impl{ptr_to}§§\use{pointer}§ … … 3651 3724 \end{lstlisting} 3652 3725 3653 Assignment to pointers is more complicated than is the case with other types, because the target's type can have extra type qualifiers in the pointed-at type: a ``©T *©'' can be assigned to a ``©const T *©'', a ``©volatile T *©'', and a ``©const volatile T *©''. 3654 Again, the pointed-at type is passed in, so that assertions can connect these specifications to the ``©ptr_to©'' specifications. 3726 Assignment to pointers is more complicated than is the case with other types, because the target's type can have extra type qualifiers in the pointed-at type: a ``\lstinline@T *@'' can be assigned to a ``\lstinline@const T *@'', a ``\lstinline@volatile T *@'', and a ``\lstinline@const volatile T *@''. 3727 Again, the pointed-at type is passed in, so that assertions can connect these specifications to the 3728 ``\lstinline@ptr_to@'' specifications. 3655 3729 \begin{lstlisting} 3656 3730 trait m_l_ptr_to( otype P | m_l_pointer( P ),§\use{m_l_pointer}§§\impl{m_l_ptr_to}§ otype T | ptr_to( P, T )§\use{ptr_to}§ { … … 3681 3755 }; 3682 3756 \end{lstlisting} 3683 The assertion ``©| m_l_ptr_like( Safe_ptr, const int * )©'' should be read as ``©Safe_ptr© is a pointer type like ©const int *©''. 3684 This 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. 3757 The assertion ``\lstinline@| m_l_ptr_like( Safe_ptr, const int * )@'' should be read as 3758 ``\lstinline@Safe_ptr@ is a pointer type like \lstinline@const int *@''. 3759 This specification has two defects, compared to the original four: there is no automatic assertion that dereferencing a 3760 \lstinline@MyP@ produces an lvalue of the type that \lstinline@CP@ points at, and the 3761 ``\lstinline@|m_l_pointer( CP )@'' assertion provides only a weak assurance that the argument passed to \lstinline@CP@ really is a pointer type. 3685 3762 3686 3763 … … 3688 3765 3689 3766 Different operators often have related meanings; 3690 for instance, in C, ``©+©'', ``©+=©'', and the two versions of ``©++©'' perform variations of addition. 3767 for instance, in C, ``\lstinline@+@'', 3768 ``\lstinline@+=@'', and the two versions of ``\lstinline@++@'' perform variations of addition. 3691 3769 Languages like {\CC} and Ada allow programmers to define operators for new types, but do not require that these relationships be preserved, or even that all of the operators be implemented. 3692 3770 Completeness and consistency is left to the good taste and discretion of the programmer. … … 3701 3779 The different comparison operators have obvious relationships, but there is no obvious subset of the operations to use in the implementation of the others. 3702 3780 However, it is usually convenient to implement a single comparison function that returns a negative integer, 0, or a positive integer if its first argument is respectively less than, equal to, or greater than its second argument; 3703 the library function ©strcmp©is an example.3704 3705 C and \CFA have an extra, non-obvious comparison operator: `` ©!©'', logical negation, returns 1 if its operand compares equal to 0, and 0 otherwise.3781 the library function \lstinline@strcmp@ is an example. 3782 3783 C and \CFA have an extra, non-obvious comparison operator: ``\lstinline@!@'', logical negation, returns 1 if its operand compares equal to 0, and 0 otherwise. 3706 3784 \begin{lstlisting} 3707 3785 trait comparable( otype T ) { … … 3751 3829 \end{lstlisting} 3752 3830 3753 Note that, although an arithmetic type would certainly provide comparison functions, and an integral type would provide arithmetic operations, there does not have to be any relationship among ©int_base©, ©arith_base© and ©comparable©. 3831 Note that, although an arithmetic type would certainly provide comparison functions, and an integral type would provide arithmetic operations, there does not have to be any relationship among 3832 \lstinline@int_base@, \lstinline@arith_base@ and \lstinline@comparable@. 3754 3833 Note also that these declarations provide guidance and assistance, but they do not define an absolutely minimal set of requirements. 3755 A truly minimal implementation of an arithmetic type might only provide ©0©, ©1©, and ©?-=?©, which would be used by polymorphic ©?+=?©, ©?*=?©, and ©?/=?©functions.3756 3757 Note also that ©short©is an integer type in C11 terms, but has no operations!3834 A truly minimal implementation of an arithmetic type might only provide \lstinline@0@, \lstinline@1@, and \lstinline@?-=?@, which would be used by polymorphic \lstinline@?+=?@, \lstinline@?*=?@, and \lstinline@?/=?@ functions. 3835 3836 Note also that \lstinline@short@ is an integer type in C11 terms, but has no operations! 3758 3837 3759 3838 … … 3762 3841 3763 3842 Restrict allowed to qualify anything, or type/dtype parameters, but only affects pointers. 3764 This gets into ©noalias©territory.3765 Qualifying anything (`` ©short restrict rs©'') means pointer parameters of ©?++©, etc, would need restrict qualifiers.3843 This gets into \lstinline@noalias@ territory. 3844 Qualifying anything (``\lstinline@short restrict rs@'') means pointer parameters of \lstinline@?++@, etc, would need restrict qualifiers. 3766 3845 3767 3846 Enumerated types. … … 3773 3852 Color, enum Color ) really make sense? ?++ does, but it adds (int)1. 3774 3853 3775 Operators on {,signed,unsigned} char and other small types. ©?<?©harmless;3854 Operators on {,signed,unsigned} char and other small types. \lstinline@?<?@ harmless; 3776 3855 ?*? questionable for chars. 3777 3856 Generic selections make these choices visible. 3778 Safe conversion operators? Predefined ``promotion'' function? 3779 3780 ©register© assignment might be handled as assignment to a temporary with copying back and forth, but copying must not be done by assignment. 3781 3782 Don't use ©ptrdiff_t© by name in the predefineds. 3857 Safe conversion operators? Predefined 3858 ``promotion'' function? 3859 3860 \lstinline@register@ assignment might be handled as assignment to a temporary with copying back and forth, but copying must not be done by assignment. 3861 3862 Don't use \lstinline@ptrdiff_t@ by name in the predefineds. 3783 3863 3784 3864 Polymorphic objects.
Note:
See TracChangeset
for help on using the changeset viewer.