Changeset bc17be98 for doc/theses/jiada_liang_MMath/CFAenum.tex
- Timestamp:
- Jun 12, 2024, 9:21:05 AM (5 months ago)
- Branches:
- master
- Children:
- d280784
- Parents:
- c033405
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
rc033405 rbc17be98 25 25 26 26 In 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 .27 There 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. 28 28 29 29 The \CFA type-system allows extensive overloading, including enumerators. … … 33 33 enum E1 { First, Second, Third, Fourth }; 34 34 enum E2 { @Fourth@, @Third@, @Second@, @First@ }; $\C{// same enumerator names}$ 35 E1 p() { return Third; } $\C{// return}$36 E2 p() { return Fourth; }35 E1 f() { return Third; } $\C{// overloaded functions, different return types}$ 36 E2 f() { return Fourth; } 37 37 void foo() { 38 38 E1 e1 = First; E2 e2 = First; $\C{// initialization}$ 39 39 e1 = Second; e2 = Second; $\C{// assignment}$ 40 e1 = p(); e2 = p(); $\C{// function call}$40 e1 = f(); e2 = f(); $\C{// function call}$ 41 41 int i = @E1.@First + @E2.@First; $\C{// disambiguate with qualification}$ 42 42 int j = @(E1)@First + @(E2)@First; $\C{// disambiguate with cast}$ 43 43 } 44 44 \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. 46 Experience 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. 47 Any ambiguity can be resolved using qualification or casting. 47 48 48 49 … … 63 64 It 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}). 64 65 \begin{cfa} 65 with ( @Week@, @RGB@ ) { $\C{// type names}$66 week = @Sun@; $\C{// no qualification}$66 with ( @Week@, @RGB@ ) { $\C{// type names}$ 67 week = @Sun@; $\C{// no qualification}$ 67 68 rgb = @Green@; 68 69 } 69 70 \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. 71 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 this localized scenario. 72 71 73 72 74 \section{Enumeration Trait} … … 184 186 % \end{cfa} 185 187 % Note the ability to print all of an enumerator's properties. 186 187 188 188 189 … … 371 372 372 373 373 374 374 \section{Enumerated Arrays} 375 375 Enumerated array use an \CFA array as their index. … … 382 382 sout | "Colour Code of Orange is " | colourCode[Orange]; 383 383 \end{cfa} 384 384 385 385 386 \section{Planet Example}
Note: See TracChangeset
for help on using the changeset viewer.