Ignore:
Timestamp:
Jul 29, 2024, 4:55:50 PM (4 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
dd78dbc
Parents:
f3d2a4f
Message:

Add CEnum.tex

File:
1 edited

Legend:

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

    rf3d2a4f r09bdf2d  
    3030Opaque enum is a special CFA enumeration type, where the internal representation is chosen by the compiler and hidden from users.
    3131Compared 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.
     32Enumerators of opaque enum cannot have initializer. Declaring initializer in the body of opaque enum results in a compile time error.
    3333\begin{cfa}
    3434enum@()@ Planets { MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE };
     
    114114\subsection{Value Conversion}
    115115C 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.
     116Correspondingly, \CFA has an implicit conversion from a typed enumerator to its base type. The feature that allows Typed enumeration
     117seemlyless used
    117118\begin{cfa}
    118119char currency = Dollar;
     
    120121foo( Fred );
    121122\end{cfa}
    122 % \CFA enumeration being resolved as its base type because \CFA inserts an implicit @value()@ call on an \CFA enumeration.
     123
    123124During the resolution of expression e with \CFA enumeration type, \CFA adds @value(e)@ as an additional candidate with an extra \newterm{value} cost.
    124125For expression @char currency = Dollar@, the is no defined conversion from Dollar (\CFA enumeration) type to basic type and the conversion cost is @infinite@,
     
    154155try to resolve it as a @CfaEnum@, rather to insert a @value@ conversion.
    155156
    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}
     158Explicit conversion is allowed on \CFA enumeration to an integral type, in which case \CFA converts \CFA enumeration into its underlying representation,
     159which is its @position@.
    159160
    160161\section{Auto Initialization}
Note: See TracChangeset for help on using the changeset viewer.