Changes in / [46b4259:473d8c82]


Ignore:
Location:
doc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/LaTeXmacros/common.tex

    r46b4259 r473d8c82  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Thu Aug  4 13:22:46 2016
    14 %% Update Count     : 230
     13%% Last Modified On : Tue Aug  2 17:02:02 2016
     14%% Update Count     : 228
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    255255literate={-}{\raisebox{-0.15ex}{\texttt{-}}}1 {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1
    256256        {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 {_}{\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}1 {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
    257         {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2,
     257        {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {...}{$\dots$}2,
    258258}%
    259259
  • doc/user/user.tex

    r46b4259 r473d8c82  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun Aug 14 08:23:06 2016
    14 %% Update Count     : 1323
     13%% Last Modified On : Tue Aug  2 17:39:02 2016
     14%% Update Count     : 1286
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    317317
    318318\item
    319 \Indexc{-no-include-stdhdr}\index{compilation option!-no-include-stdhdr@©-no-include-stdhdr©}
     319\Indexc{-no-include-std}\index{compilation option!-no-include-std@©-no-include-std©}
    320320Do not supply ©extern "C"© wrappers for \Celeven standard include files (see~\VRef{s:StandardHeaders}).
    321321\textbf{This option is \emph{not} the default.}
     
    807807
    808808
    809 \section{Backquote Identifiers}
    810 \label{s:BackquoteIdentifiers}
    811 
    812 \CFA accommodates keyword clashes by syntactic transformations using the \CFA backquote escape-mechanism:
    813 \begin{lstlisting}
    814 int `otype` = 3;                                // make keyword an identifier
    815 double `choose` = 3.5;
    816 \end{lstlisting}
    817 Programs can be converted easily by enclosing keyword identifiers in backquotes, and the backquotes can be removed later when the identifier name is changed to an non-keyword name.
    818 Clashes in C header files (see~\VRef{s:StandardHeaders}) can be handled automatically using the preprocessor, ©#include_next© and ©-I filename©:
    819 \begin{lstlisting}
    820 // include file uses the CFA keyword "otype".
    821 #if ! defined( otype )                  // nesting ?
    822 #define otype `otype`
    823 #define __CFA_BFD_H__
    824 #endif // ! otype
    825 
    826 #include_next <bfd.h>                   // must have internal check for multiple expansion
    827 
    828 #if defined( otype ) && defined( __CFA_BFD_H__ )        // reset only if set
    829 #undef otype
    830 #undef __CFA_BFD_H__
    831 #endif // otype && __CFA_BFD_H__
    832 \end{lstlisting}
    833 
    834 
    835809\section{Type Operators}
    836810
     
    10371011Alternatively, prototype definitions can be eliminated by using a two-pass compilation, and implicitly creating header files for exports.
    10381012The former is easy to do, while the latter is more complex.
    1039 
    1040 Furthermore, named arguments do not work well in a \CFA-style programming-languages because they potentially introduces a new criteria for type matching.
    1041 For example, it is technically possible to disambiguate between these two overloaded definitions of ©f© based on named arguments at the call site:
    1042 \begin{lstlisting}
    1043 int f( int i, int j );
    1044 int f( int x, double y );
    1045 
    1046 f( j : 3, i : 4 );                              §\C{// 1st f}§
    1047 f( x : 7, y : 8.1 );                    §\C{// 2nd f}§
    1048 f( 4, 5 );                                              §\C{// ambiguous call}§
    1049 \end{lstlisting}
    1050 However, named arguments compound routine resolution in conjunction with conversions:
    1051 \begin{lstlisting}
    1052 f( i : 3, 5.7 );                                §\C{// ambiguous call ?}§
    1053 \end{lstlisting}
    1054 Depending on the cost associated with named arguments, this call could be resolvable or ambiguous.
    1055 Adding named argument into the routine resolution algorithm does not seem worth the complexity.
    1056 Therefore, \CFA does \emph{not} attempt to support named arguments.
     1013Currently, \CFA does \emph{not} attempt to support named arguments.
    10571014
    10581015\item[Default Arguments]
     
    10641021the allowable positional calls are:
    10651022\begin{lstlisting}
    1066 p();                                                    §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
    1067 p( 4 );                                                 §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
    1068 p( 4, 4 );                                              §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
    1069 p( 4, 4, 4 );                                   §\C{// rewrite $\Rightarrow$ p( 4, 4, 4 )}§
     1023p();                            §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
     1024p( 4 );                         §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
     1025p( 4, 4 );                      §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
     1026p( 4, 4, 4 );           §\C{// rewrite $\Rightarrow$ p( 4, 4, 4 )}§
    10701027// empty arguments
    1071 p(  , 4, 4 );                                   §\C{// rewrite $\Rightarrow$ p( 1, 4, 4 )}§
    1072 p( 4,  , 4 );                                   §\C{// rewrite $\Rightarrow$ p( 4, 2, 4 )}§
    1073 p( 4, 4,   );                                   §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
    1074 p( 4,  ,   );                                   §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
    1075 p(  , 4,   );                                   §\C{// rewrite $\Rightarrow$ p( 1, 4, 3 )}§
    1076 p(  ,  , 4 );                                   §\C{// rewrite $\Rightarrow$ p( 1, 2, 4 )}§
    1077 p(  ,  ,   );                                   §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
     1028p(  , 4, 4 );           §\C{// rewrite $\Rightarrow$ p( 1, 4, 4 )}§
     1029p( 4,  , 4 );           §\C{// rewrite $\Rightarrow$ p( 4, 2, 4 )}§
     1030p( 4, 4,   );           §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
     1031p( 4,  ,   );           §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
     1032p(  , 4,   );           §\C{// rewrite $\Rightarrow$ p( 1, 4, 3 )}§
     1033p(  ,  , 4 );           §\C{// rewrite $\Rightarrow$ p( 1, 2, 4 )}§
     1034p(  ,  ,   );           §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
    10781035\end{lstlisting}
    10791036Here the missing arguments are inserted from the default values in the parameter list.
     
    11101067The conflict occurs because both named and ellipse arguments must appear after positional arguments, giving two possibilities:
    11111068\begin{lstlisting}
    1112 p( /* positional */, ... , /* named */ );
    1113 p( /* positional */, /* named */, ... );
     1069p( /* positional */, . . ., /* named */ );
     1070p( /* positional */, /* named */, . . . );
    11141071\end{lstlisting}
    11151072While it is possible to implement both approaches, the first possibly is more complex than the second, \eg:
    11161073\begin{lstlisting}
    1117 p( int x, int y, int z, ... );
    1118 p( 1, 4, 5, 6, z : 3, y : 2 ); §\C{// assume p( /* positional */, ... , /* named */ );}§
    1119 p( 1, z : 3, y : 2, 4, 5, 6 ); §\C{// assume p( /* positional */, /* named */, ... );}§
     1074p( int x, int y, int z, . . . );
     1075p( 1, 4, 5, 6, z : 3, y : 2 ); §\C{// assume p( /* positional */, . . ., /* named */ );}§
     1076p( 1, z : 3, y : 2, 4, 5, 6 ); §\C{// assume p( /* positional */, /* named */, . . . );}§
    11201077\end{lstlisting}
    11211078In the first call, it is necessary for the programmer to conceptually rewrite the call, changing named arguments into positional, before knowing where the ellipse arguments begin.
     
    11251082The problem is exacerbated with default arguments, \eg:
    11261083\begin{lstlisting}
    1127 void p( int x, int y = 2, int z = 3... );
    1128 p( 1, 4, 5, 6, z : 3 );         §\C{// assume p( /* positional */, ... , /* named */ );}§
    1129 p( 1, z : 3, 4, 5, 6 );         §\C{// assume p( /* positional */, /* named */, ... );}§
     1084void p( int x, int y = 2, int z = 3. . . );
     1085p( 1, 4, 5, 6, z : 3 );         §\C{// assume p( /* positional */, . . ., /* named */ );}§
     1086p( 1, z : 3, 4, 5, 6 );         §\C{// assume p( /* positional */, /* named */, . . . );}§
    11301087\end{lstlisting}
    11311088The first call is an error because arguments 4 and 5 are actually positional not ellipse arguments;
     
    11721129\subsection{Type Nesting}
    11731130
    1174 \CFA allows \Index{type nesting}, and type qualification of the nested typres (see \VRef[Figure]{f:TypeNestingQualification}), where as C hoists\index{type hoisting} (refactors) nested types into the enclosing scope and has no type qualification.
     1131\CFA allows \Index{type nesting}, and type qualification of the nested types (see \VRef[Figure]{f:TypeNestingQualification}), where as C hoists\index{type hoisting} (refactors) nested types into the enclosing scope and has no type qualification.
    11751132\begin{figure}
    1176 \centering
    11771133\begin{tabular}{@{}l@{\hspace{3em}}l|l@{}}
    11781134\multicolumn{1}{c@{\hspace{3em}}}{\textbf{C Type Nesting}}      & \multicolumn{1}{c}{\textbf{C Implicit Hoisting}}      & \multicolumn{1}{|c}{\textbf{\CFA}}    \\
     
    14411397Mass assignment has the following form:
    14421398\begin{lstlisting}
    1443 [ §\emph{lvalue}§, ... , §\emph{lvalue}§ ] = §\emph{expr}§;
     1399[ §\emph{lvalue}§, ..., §\emph{lvalue}§ ] = §\emph{expr}§;
    14441400\end{lstlisting}
    14451401\index{lvalue}
     
    14811437Multiple assignment has the following form:
    14821438\begin{lstlisting}
    1483 [ §\emph{lvalue}§, ... , §\emph{lvalue}§ ] = [ §\emph{expr}§, ... , §\emph{expr}§ ];
     1439[ §\emph{lvalue}§, . . ., §\emph{lvalue}§ ] = [ §\emph{expr}§, . . ., §\emph{expr}§ ];
    14841440\end{lstlisting}
    14851441\index{lvalue}
     
    19171873\begin{lstlisting}
    19181874switch ( i ) {
    1919   case ®1, 3, 5®:
     1875  ®case 1, 3, 5®:
    19201876        ...
    1921   case ®2, 4, 6®:
     1877  ®case 2, 4, 6®:
    19221878        ...
    19231879}
     
    19501906\begin{lstlisting}
    19511907switch ( i ) {
    1952   case ®1~5:®
     1908  ®case 1~5:®
    19531909        ...
    1954   case ®10~15:®
     1910  ®case 10~15:®
    19551911        ...
    19561912}
     
    19591915\begin{lstlisting}
    19601916switch ( i )
    1961   case ®1 ... 5®:
     1917  case 1 ... 5:
    19621918        ...
    1963   case ®10 ... 15®:
     1919  case 10 ... 15:
    19641920        ...
    19651921}
     
    44134369
    44144370
    4415 \section{Incompatible}
    4416 
    4417 The following incompatibles exist between \CFA and C, and are similar to Annex C for \CC~\cite{ANSI14:C++}.
    4418 
    4419 \begin{enumerate}
    4420 \item
    4421 \begin{description}
    4422 \item[Change:] add new keywords \\
    4423 New keywords are added to \CFA (see~\VRef{s:NewKeywords}).
    4424 \item[Rationale:] keywords added to implement new semantics of \CFA.
    4425 \item[Effect on original feature:] change to semantics of well-defined feature. \\
    4426 Any ISO C programs using these keywords as identifiers are invalid \CFA programs.
    4427 \item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism (see~\VRef{s:BackquoteIdentifiers}):
    4428 \item[How widely used:] clashes among new \CFA keywords and existing identifiers are rare.
    4429 \end{description}
    4430 
    4431 \item
    4432 \begin{description}
    4433 \item[Change:] type of character literal ©int© to ©char© to allow more intuitive overloading:
    4434 \begin{lstlisting}
    4435 int rtn( int i );
    4436 int rtn( char c );
    4437 rtn( 'x' );                                             §\C{// programmer expects 2nd rtn to be called}§
    4438 \end{lstlisting}
    4439 \item[Rationale:] it is more intuitive for the call to ©rtn© to match the second version of definition of ©rtn© rather than the first.
    4440 In particular, output of ©char© variable now print a character rather than the decimal ASCII value of the character.
    4441 \begin{lstlisting}
    4442 sout | 'x' | " " | (int)'x' | endl;
    4443 x 120
    4444 \end{lstlisting}
    4445 Having to cast ©'x'© to ©char© is non-intuitive.
    4446 \item[Effect on original feature:] change to semantics of well-defined feature that depend on:
    4447 \begin{lstlisting}
    4448 sizeof( 'x' ) == sizeof( int )
    4449 \end{lstlisting}
    4450 no long work the same in \CFA programs.
    4451 \item[Difficulty of converting:] simple
    4452 \item[How widely used:] programs that depend upon ©sizeof( 'x' )© are rare and can be changed to ©sizeof(char)©.
    4453 \end{description}
    4454 
    4455 \item
    4456 \begin{description}
    4457 \item[Change:] make string literals ©const©:
    4458 \begin{lstlisting}
    4459 char * p = "abc";                               §\C{// valid in C, deprecated in \CFA}§
    4460 char * q = expr ? "abc" : "de"; §\C{// valid in C, invalid in \CFA}§
    4461 \end{lstlisting}
    4462 The type of a string literal is changed from ©[] char© to ©const [] char©.
    4463 Similarly, the type of a wide string literal is changed from ©[] wchar_t© to ©const [] wchar_t©.
    4464 \item[Rationale:] This change is a safety issue:
    4465 \begin{lstlisting}
    4466 char * p = "abc";
    4467 p[0] = 'w';                                             §\C{// segment fault or change constant literal}§
    4468 \end{lstlisting}
    4469 The same problem occurs when passing a string literal to a routine that changes its argument.
    4470 \item[Effect on original feature:] change to semantics of well-defined feature.
    4471 \item[Difficulty of converting:] simple syntactic transformation, because string literals can be converted to ©char *©.
    4472 \item[How widely used:] programs that have a legitimate reason to treat string literals as pointers to potentially modifiable memory are rare.
    4473 \end{description}
    4474 
    4475 \item
    4476 \begin{description}
    4477 \item[Change:] remove \newterm{tentative definitions}, which only occurs at file scope:
    4478 \begin{lstlisting}
    4479 int i;                                                  §\C{// forward definition}§
    4480 int *j = ®&i®;                                  §\C{// forward reference, valid in C, invalid in \CFA}§
    4481 int i = 0;                                              §\C{// definition}§
    4482 \end{lstlisting}
    4483 is valid in C, and invalid in \CFA because duplicate overloaded object definitions at the same scope level are disallowed.
    4484 This change makes it impossible to define mutually referential file-local static objects, if initializers are restricted to the syntactic forms of C. For example,
    4485 \begin{lstlisting}
    4486 struct X { int i; struct X *next; };
    4487 static struct X a;                              §\C{// forward definition}§
    4488 static struct X b = { 0, ®&a® };        §\C{// forward reference, valid in C, invalid in \CFA}§
    4489 static struct X a = { 1, &b };  §\C{// definition}§
    4490 \end{lstlisting}
    4491 \item[Rationale:] avoids having different initialization rules for builtin types and userdefined types.
    4492 \item[Effect on original feature:] change to semantics of well-defined feature.
    4493 \item[Difficulty of converting:] the initializer for one of a set of mutually-referential file-local static objects must invoke a routine call to achieve the initialization.
    4494 \item[How widely used:] seldom
    4495 \end{description}
    4496 
    4497 \item
    4498 \begin{description}
    4499 \item[Change:] have ©struct© introduce a scope for nested types:
    4500 \begin{lstlisting}
    4501 enum ®Colour® { R, G, B, Y, C, M };
    4502 struct Person {
    4503         enum ®Colour® { R, G, B };      §\C{// nested type}§
    4504         struct Face {                           §\C{// nested type}§
    4505                 ®Colour® Eyes, Hair;    §\C{// type defined outside (1 level)}§
    4506         };
    4507         ß.ß®Colour® shirt;                      §\C{// type defined outside (top level)}§
    4508         ®Colour® pants;                         §\C{// type defined same level}§
    4509         Face looks[10];                         §\C{// type defined same level}§
    4510 };
    4511 ®Colour® c = R;                                 §\C{// type/enum defined same level}§
    4512 Personß.ß®Colour® pc = Personß.ßR;      §\C{// type/enum defined inside}§
    4513 Personß.ßFace pretty;                   §\C{// type defined inside}§
    4514 \end{lstlisting}
    4515 In C, the name of the nested types belongs to the same scope as the name of the outermost enclosing structure, i.e., the nested types are hoisted to the scope of the outer-most type, which is not useful and confusing.
    4516 \CFA is C \emph{incompatible} on this issue, and provides semantics similar to \Index*[C++]{\CC}.
    4517 Nested types are not hoisted and can be referenced using the field selection operator ``©.©'', unlike the \CC scope-resolution operator ``©::©''.
    4518 \item[Rationale:] ©struct© scope is crucial to \CFA as an information structuring and hiding mechanism.
    4519 \item[Effect on original feature:] change to semantics of well-defined feature.
    4520 \item[Difficulty of converting:] Semantic transformation.
    4521 \item[How widely used:] C programs rarely have nest types because they are equivalent to the hoisted version.
    4522 \end{description}
    4523 
    4524 \item
    4525 \begin{description}
    4526 \item[Change:] In C++, the name of a nested class is local to its enclosing class.
    4527 \item[Rationale:] C++ classes have member functions which require that classes establish scopes.
    4528 \item[Difficulty of converting:] Semantic transformation. To make the struct type name visible in the scope of the enclosing struct, the struct tag could be declared in the scope of the enclosing struct, before the enclosing struct is defined. Example:
    4529 \begin{lstlisting}
    4530 struct Y;                                               §\C{// struct Y and struct X are at the same scope}§
    4531 struct X {
    4532 struct Y { /* ... */ } y;
    4533 };
    4534 \end{lstlisting}
    4535 All the definitions of C struct types enclosed in other struct definitions and accessed outside the scope of the enclosing struct could be exported to the scope of the enclosing struct.
    4536 Note: this is a consequence of the difference in scope rules, which is documented in 3.3.
    4537 \item[How widely used:] Seldom.
    4538 \end{description}
    4539 
    4540 \item
    4541 \begin{description}
    4542 \item[Change:] comma expression is disallowed as subscript
    4543 \item[Rationale:] safety issue to prevent subscripting error for multidimensional arrays: ©x[i,j]© instead of ©x[i][j]©, and this syntactic form then taken by \CFA for new style arrays.
    4544 \item[Effect on original feature:] change to semantics of well-defined feature.
    4545 \item[Difficulty of converting:] semantic transformation of ©x[i,j]© to ©x[(i,j)]©
    4546 \item[How widely used:] seldom.
    4547 \end{description}
    4548 \end{enumerate}
    4549 
    4550 
    45514371\section{New Keywords}
    45524372\label{s:NewKeywords}
    45534373
    45544374\begin{quote2}
    4555 \begin{tabular}{lll}
    4556 ©catch©                 & ©fallthrough© & ©otype©               \\
    4557 ©catchResume©   & ©fallthru©    & ©throw©               \\
    4558 ©choose©                & ©finally©             & ©throwResume© \\
    4559 ©disable©               & ©forall©              & ©trait©               \\
    4560 ©dtype©                 & ©ftype©               & ©try©                 \\
    4561 ©enable©                & ©lvalue©              &                               \\
     4375\begin{tabular}{ll}
     4376©catch©                 & ©lvalue©              \\
     4377©catchResume©   &                               \\
     4378©choose©                & ©otype©               \\
     4379                                &                               \\
     4380©disable©               & ©throw©               \\
     4381©dtype©                 & ©throwResume© \\
     4382                                & ©trait©               \\
     4383©enable©                & ©try©                 \\
     4384                                &                               \\
     4385©fallthrough©                                   \\
     4386©fallthru©                                              \\
     4387©finally©                                               \\
     4388©forall©                                                \\
     4389©ftype©                                                 \\
    45624390\end{tabular}
    45634391\end{quote2}
     
    45674395\label{s:StandardHeaders}
    45684396
    4569 C prescribes the following standard header-files~\cite[\S~7.1.2]{C11}:
     4397C prescribes the following standard header-files:
    45704398\begin{quote2}
    45714399\begin{minipage}{\linewidth}
     
    45844412\end{minipage}
    45854413\end{quote2}
    4586 For the prescribed head-files, \CFA implicitly wraps their includes in an ©extern "C"©;
     4414For the prescribed head-files, \CFA implicit wraps their includes in an ©extern "C"©;
    45874415hence, names in these include files are not mangled\index{mangling!name} (see~\VRef{s:Interoperability}).
    45884416All other C header files must be explicitly wrapped in ©extern "C"© to prevent name mangling.
     4417
     4418
     4419\section{Incompatible}
     4420
     4421The following incompatibles exist between \CFA and C, and are similar to Annex C for \CC~\cite{ANSI14:C++}.
     4422
     4423\begin{enumerate}
     4424\item
     4425\begin{description}
     4426\item[Change:] add new keywords (see~\VRef{s:NewKeywords}) \\
     4427New keywords are added to \CFA.
     4428\item[Rationale:] keywords added to implement new semantics of \CFA.
     4429\item[Effect on original feature:] change to semantics of well-defined feature. \\
     4430Any ISO C programs using these keywords as identifiers are invalid \CFA programs.
     4431\item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
     4432\begin{lstlisting}
     4433int `otype` = 3;                                // make keyword an identifier
     4434double `choose` = 3.5;
     4435\end{lstlisting}
     4436Programs can be converted automatically by enclosing keyword identifiers in backquotes, and the backquotes can be remove later when the identifier name is changed.
     4437Clashes in C system libraries (include files) can be handled automatically using preprocessor, ©#include_next© and ©-Ifilename©:
     4438\begin{lstlisting}
     4439// include file uses the CFA keyword "otype".
     4440#if ! defined( otype )                  // nesting ?
     4441#define otype `otype`
     4442#define __CFA_BFD_H__
     4443#endif // ! otype
     4444
     4445#include_next <bfd.h>                   // must have internal check for multiple expansion
     4446
     4447#if defined( otype ) && defined( __CFA_BFD_H__ )        // reset only if set
     4448#undef otype
     4449#undef __CFA_BFD_H__
     4450#endif // otype && __CFA_BFD_H__
     4451\end{lstlisting}
     4452\item[How widely used:] clashes among new \CFA keywords and existing identifiers are rare.
     4453\end{description}
     4454
     4455\item
     4456\begin{description}
     4457\item[Change:] type of character literal ©int© to ©char© to allow more intuitive overloading:
     4458\begin{lstlisting}
     4459int rtn( int i );
     4460int rtn( char c );
     4461rtn( 'x' );                                             // programmer expects 2nd rtn to be called
     4462\end{lstlisting}
     4463\item[Rationale:] it is more intuitive for the call to ©rtn© to match the second version of definition of ©rtn© rather than the first.
     4464In particular, output of ©char© variable now print a character rather than the decimal ASCII value of the character.
     4465\begin{lstlisting}
     4466sout | 'x' | " " | (int)'x' | endl;
     4467x 120
     4468\end{lstlisting}
     4469Having to cast ©'x'© to ©char© is non-intuitive.
     4470\item[Effect on original feature:] change to semantics of well-defined feature that depend on:
     4471\begin{lstlisting}
     4472sizeof( 'x' ) == sizeof( int )
     4473\end{lstlisting}
     4474no long work the same in \CFA programs.
     4475\item[Difficulty of converting:] simple
     4476\item[How widely used:] programs that depend upon ©sizeof( 'x' )© are rare and can be changed to ©sizeof(char)©.
     4477\end{description}
     4478
     4479\item
     4480\begin{description}
     4481\item[Change:] make string literals ©const©:
     4482\begin{lstlisting}
     4483char * p = "abc";                               // valid in C, deprecated in §\CFA§
     4484char * q = expr ? "abc" : "de"; // valid in C, invalid in §\CFA§
     4485\end{lstlisting}
     4486The type of a string literal is changed from ©[] char© to ©const [] char©.
     4487Similarly, the type of a wide string literal is changed from ©[] wchar_t© to ©const [] wchar_t©.
     4488\item[Rationale:] This change is a safety issue:
     4489\begin{lstlisting}
     4490char * p = "abc";
     4491p[0] = 'w';                                             // segment fault or change constant literal
     4492\end{lstlisting}
     4493The same problem occurs when passing a string literal to a routine that changes its argument.
     4494\item[Effect on original feature:] change to semantics of well-defined feature.
     4495\item[Difficulty of converting:] simple syntactic transformation, because string literals can be converted to ©char *©.
     4496\item[How widely used:] programs that have a legitimate reason to treat string literals as pointers to potentially modifiable memory are rare.
     4497\end{description}
     4498
     4499\item
     4500\begin{description}
     4501\item[Change:] remove \newterm{tentative definitions}, which only occurs at file scope:
     4502\begin{lstlisting}
     4503int i;                                                  // forward definition
     4504int *j = ®&i®;                                  // forward reference, valid in C, invalid in §\CFA§
     4505int i = 0;                                              // definition
     4506\end{lstlisting}
     4507is valid in C, and invalid in \CFA because duplicate overloaded object definitions at the same scope level are disallowed.
     4508This change makes it impossible to define mutually referential file-local static objects, if initializers are restricted to the syntactic forms of C. For example,
     4509\begin{lstlisting}
     4510struct X { int i; struct X *next; };
     4511static struct X a;                              // forward definition
     4512static struct X b = { 0, ®&a® };        // forward reference, valid in C, invalid in §\CFA§
     4513static struct X a = { 1, &b };  // definition
     4514\end{lstlisting}
     4515\item[Rationale:] avoids having different initialization rules for builtin types and userdefined types.
     4516\item[Effect on original feature:] change to semantics of well-defined feature.
     4517\item[Difficulty of converting:] the initializer for one of a set of mutually-referential file-local static objects must invoke a routine call to achieve the initialization.
     4518\item[How widely used:] seldom
     4519\end{description}
     4520
     4521\item
     4522\begin{description}
     4523\item[Change:] have ©struct© introduce a scope for nested types
     4524In C, the name of the nested types belongs to the same scope as the name of the outermost enclosing
     4525Example:
     4526\begin{lstlisting}
     4527enum ®Colour® { R, G, B, Y, C, M };
     4528struct Person {
     4529        enum ®Colour® { R, G, B };      // nested type
     4530        struct Face {                           // nested type
     4531                ®Colour® Eyes, Hair;            // type defined outside (1 level)
     4532        };
     4533        ß.ß®Colour® shirt;                              // type defined outside (top level)
     4534        ®Colour® pants;                         // type defined same level
     4535        Face looks[10];                         // type defined same level
     4536};
     4537®Colour® c = R;                                 // type/enum defined same level
     4538Personß.ß®Colour® pc = Personß.ßR;      // type/enum defined inside
     4539Personß.ßFace pretty;                           // type defined inside
     4540\end{lstlisting}
     4541\item[Rationale:] ©struct© scope is crucial to \CFA as an information structuring and hiding mechanism.
     4542\item[Effect on original feature:] change to semantics of well-defined feature.
     4543\item[Difficulty of converting:] Semantic transformation.
     4544\item[How widely used:] C programs rarely have nest types because they are equivalent to the hoisted version.
     4545
     4546\CFA is C \emph{incompatible} on this issue, and provides semantics similar to \Index*[C++]{\CC}.
     4547Nested types are not hoisted and can be referenced using the field selection operator ``©.©'', unlike the \CC scope-resolution operator ``©::©''.
     4548Given that nested types in C are equivalent to not using them, \ie they are essentially useless, it is unlikely there are any realistic usages that break because of this incompatibility.
     4549\end{description}
     4550
     4551\item
     4552\begin{description}
     4553\item[Change:] In C++, the name of a nested class is local to its enclosing class.
     4554\item[Rationale:] C++ classes have member functions which require that classes establish scopes.
     4555\item[Difficulty of converting:] Semantic transformation. To make the struct type name visible in the scope of the enclosing struct, the struct tag could be declared in the scope of the enclosing struct, before the enclosing struct is defined. Example:
     4556\begin{lstlisting}
     4557struct Y; // struct Y and struct X are at the same scope
     4558struct X {
     4559struct Y { /* ... */ } y;
     4560};
     4561\end{lstlisting}
     4562All the definitions of C struct types enclosed in other struct definitions and accessed outside the scope of the enclosing struct could be exported to the scope of the enclosing struct.
     4563Note: this is a consequence of the difference in scope rules, which is documented in 3.3.
     4564\item[How widely used:] Seldom.
     4565\end{description}
     4566
     4567\item
     4568\begin{description}
     4569\item[Change:] comma expression is disallowed as subscript
     4570\item[Rationale:] safety issue to prevent subscripting error for multidimensional arrays: ©x[i,j]© instead of ©x[i][j]©, and this syntactic form then taken by \CFA for new style arrays.
     4571\item[Effect on original feature:] change to semantics of well-defined feature.
     4572\item[Difficulty of converting:] semantic transformation of ©x[i,j]© to ©x[(i,j)]©
     4573\item[How widely used:] seldom.
     4574\end{description}
     4575\end{enumerate}
    45894576
    45904577
     
    47624749\subsection{malloc}
    47634750
    4764 \leavevmode
    47654751\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    47664752forall( otype T ) T * malloc( void );§\indexc{malloc}§
     
    47794765forall( otype T ) T * memset( T * ptr );                                // remove when default value available
    47804766\end{lstlisting}
    4781 
     4767\
    47824768
    47834769\subsection{ato / strto}
    47844770
    4785 \leavevmode
    47864771\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    47874772int ato( const char * ptr );§\indexc{ato}§
     
    48114796long double _Complex strto( const char * sptr, char ** eptr );
    48124797\end{lstlisting}
     4798\
    48134799
    48144800
    48154801\subsection{bsearch / qsort}
    48164802
    4817 \leavevmode
    48184803\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    48194804forall( otype T | { int ?<?( T, T ); } )
     
    48234808void qsort( const T * arr, size_t dimension );§\indexc{qsort}§
    48244809\end{lstlisting}
     4810\
    48254811
    48264812
    48274813\subsection{abs}
    48284814
    4829 \leavevmode
    48304815\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    48314816char abs( char );§\indexc{abs}§
     
    48404825long double abs( long double _Complex );
    48414826\end{lstlisting}
     4827\
    48424828
    48434829
    48444830\subsection{random}
    48454831
    4846 \leavevmode
    48474832\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    48484833void rand48seed( long int s );§\indexc{rand48seed}§
     
    48584843long double _Complex rand48();
    48594844\end{lstlisting}
     4845\
    48604846
    48614847
    48624848\subsection{min / max / clamp / swap}
    48634849
    4864 \leavevmode
    48654850\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    48664851forall( otype T | { int ?<?( T, T ); } )
     
    48764861void swap( T * t1, T * t2 );§\indexc{swap}§
    48774862\end{lstlisting}
     4863\
    48784864
    48794865
     
    48864872\subsection{General}
    48874873
    4888 \leavevmode
    48894874\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    48904875float fabs( float );§\indexc{fabs}§
     
    49324917long double nan( const char * );
    49334918\end{lstlisting}
     4919\
    49344920
    49354921
    49364922\subsection{Exponential}
    49374923
    4938 \leavevmode
    49394924\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    49404925float exp( float );§\indexc{exp}§
     
    49894974long double logb( long double );
    49904975\end{lstlisting}
     4976\
    49914977
    49924978
    49934979\subsection{Power}
    49944980
    4995 \leavevmode
    49964981\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    49974982float sqrt( float );§\indexc{sqrt}§
     
    50175002long double _Complex pow( long double _Complex, long double _Complex );
    50185003\end{lstlisting}
     5004\
    50195005
    50205006
    50215007\subsection{Trigonometric}
    50225008
    5023 \leavevmode
    50245009\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    50255010float sin( float );§\indexc{sin}§
     
    50735058long double atan( long double, long double );
    50745059\end{lstlisting}
     5060\
    50755061
    50765062
    50775063\subsection{Hyperbolic}
    50785064
    5079 \leavevmode
    50805065\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    50815066float sinh( float );§\indexc{sinh}§
     
    51215106long double _Complex atanh( long double _Complex );
    51225107\end{lstlisting}
     5108\
    51235109
    51245110
    51255111\subsection{Error / Gamma}
    51265112
    5127 \leavevmode
    51285113\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    51295114float erf( float );§\indexc{erf}§
     
    51525137long double tgamma( long double );
    51535138\end{lstlisting}
     5139\
    51545140
    51555141
    51565142\subsection{Nearest Integer}
    51575143
    5158 \leavevmode
    51595144\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    51605145float floor( float );§\indexc{floor}§
     
    52065191long long int llround( long double );
    52075192\end{lstlisting}
     5193\
    52085194
    52095195
    52105196\subsection{Manipulation}
    52115197
    5212 \leavevmode
    52135198\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
    52145199float copysign( float, float );§\indexc{copysign}§
     
    52475232long double scalbln( long double, long int );
    52485233\end{lstlisting}
     5234\
    52495235
    52505236
Note: See TracChangeset for help on using the changeset viewer.