Changeset bc17be98 for doc/theses


Ignore:
Timestamp:
Jun 12, 2024, 9:21:05 AM (3 weeks ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
d280784
Parents:
c033405
Message:

small proofreading changes to Cforall numeration chapter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/jiada_liang_MMath/CFAenum.tex

    rc033405 rbc17be98  
    2525
    2626In C, unscoped enumerators present a \newterm{naming problem} when multiple enumeration types appear in the same scope with duplicate enumerator names.
    27 There is no mechanism in C to resolve these naming conflicts other than renaming one of the duplicates, which may be impossible.
     27There is no mechanism in C to resolve these naming conflicts other than renaming one of the duplicates, which may be impossible if the conflict comes from system include files.
    2828
    2929The \CFA type-system allows extensive overloading, including enumerators.
     
    3333enum E1 { First, Second, Third, Fourth };
    3434enum E2 { @Fourth@, @Third@, @Second@, @First@ }; $\C{// same enumerator names}$
    35 E1 p() { return Third; }                                $\C{// return}$
    36 E2 p() { return Fourth; }
     35E1 f() { return Third; }                                $\C{// overloaded functions, different return types}$
     36E2 f() { return Fourth; }
    3737void foo() {
    3838        E1 e1 = First;   E2 e2 = First;         $\C{// initialization}$
    3939        e1 = Second;   e2 = Second;                     $\C{// assignment}$
    40         e1 = p();   e2 = p();                           $\C{// function call}$
     40        e1 = f();   e2 = f();                           $\C{// function call}$
    4141        int i = @E1.@First + @E2.@First;        $\C{// disambiguate with qualification}$
    4242        int j = @(E1)@First + @(E2)@First;      $\C{// disambiguate with cast}$
    4343}
    4444\end{cfa}
    45 \CFA overloading allows programmers to use the most meaningful names without fear of name clashes from include files.
    46 In most cases, the type system implicitly disambiguates, otherwise the programmer explicitly disambiguates using qualification or casting.
     45\CFA overloading allows programmers to use the most meaningful names without fear of name clashes within a program or from external sources, like include files.
     46Experience from \CFA developers is that the type system implicitly and correctly disambiguates the majority of overloaded names, \ie it is rare to get an incorrect selection or ambiguity, even among hundreds of overloaded variables and functions.
     47Any ambiguity can be resolved using qualification or casting.
    4748
    4849
     
    6364It is possible to toggle back to unscoping using the \CFA @with@ clause/statement (see also \CC \lstinline[language=c++]{using enum} in Section~\ref{s:C++RelatedWork}).
    6465\begin{cfa}
    65 with ( @Week@, @RGB@ ) {                        $\C{// type names}$
    66          week = @Sun@;                                  $\C{// no qualification}$
     66with ( @Week@, @RGB@ ) {                                $\C{// type names}$
     67         week = @Sun@;                                          $\C{// no qualification}$
    6768         rgb = @Green@;
    6869}
    6970\end{cfa}
    70 As in Section~\ref{s:EnumeratorVisibility}, opening multiple scoped enumerations in a @with@ can result in duplicate enumeration names, but \CFA implicit type resolution and explicit qualification/casting handle ambiguities.
     71As in Section~\ref{s:EnumeratorVisibility}, opening multiple scoped enumerations in a @with@ can result in duplicate enumeration names, but \CFA implicit type resolution and explicit qualification/casting handle this localized scenario.
     72
    7173
    7274\section{Enumeration Trait}
     
    184186% \end{cfa}
    185187% Note the ability to print all of an enumerator's properties.
    186 
    187188
    188189
     
    371372
    372373
    373 
    374374\section{Enumerated Arrays}
    375375Enumerated array use an \CFA array as their index.
     
    382382sout | "Colour Code of Orange is " | colourCode[Orange];
    383383\end{cfa}
     384
    384385
    385386\section{Planet Example}
Note: See TracChangeset for help on using the changeset viewer.