- Timestamp:
- Jul 29, 2024, 4:55:50 PM (5 weeks ago)
- Branches:
- master
- Children:
- dd78dbc
- Parents:
- f3d2a4f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
rf3d2a4f r09bdf2d 30 30 Opaque enum is a special CFA enumeration type, where the internal representation is chosen by the compiler and hidden from users. 31 31 Compared C enum, opaque enums are more restrictive in terms of typing, and cannot be implicitly converted to integers. 32 Enumerators of opaque enum cannot have initializer. Declaring initializer in the body of opaque enum results in a compile error.32 Enumerators of opaque enum cannot have initializer. Declaring initializer in the body of opaque enum results in a compile time error. 33 33 \begin{cfa} 34 34 enum@()@ Planets { MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE }; … … 114 114 \subsection{Value Conversion} 115 115 C has an implicit type conversion from an enumerator to its base type @int@. 116 Correspondingly, \CFA has an implicit conversion from a typed enumerator to its base type. 116 Correspondingly, \CFA has an implicit conversion from a typed enumerator to its base type. The feature that allows Typed enumeration 117 seemlyless used 117 118 \begin{cfa} 118 119 char currency = Dollar; … … 120 121 foo( Fred ); 121 122 \end{cfa} 122 % \CFA enumeration being resolved as its base type because \CFA inserts an implicit @value()@ call on an \CFA enumeration. 123 123 124 During the resolution of expression e with \CFA enumeration type, \CFA adds @value(e)@ as an additional candidate with an extra \newterm{value} cost. 124 125 For expression @char currency = Dollar@, the is no defined conversion from Dollar (\CFA enumeration) type to basic type and the conversion cost is @infinite@, … … 154 155 try to resolve it as a @CfaEnum@, rather to insert a @value@ conversion. 155 156 156 \subsection{ Coercion}157 While implicit conversion from a \CFA enumeration has been disabled, a explicit coercion cast to basic type is still possible to be consistent with C. In which case, 158 \CFA converts a \CFA enumeration variable as a basic type, with the value of the @position@ of the variable.157 \subsection{Explicit Conversion} 158 Explicit conversion is allowed on \CFA enumeration to an integral type, in which case \CFA converts \CFA enumeration into its underlying representation, 159 which is its @position@. 159 160 160 161 \section{Auto Initialization}
Note: See TracChangeset
for help on using the changeset viewer.