Changeset c4aca65 for doc/theses/jiada_liang_MMath/Cenum.tex
- Timestamp:
- Aug 8, 2024, 5:25:41 PM (20 hours ago)
- Branches:
- master
- Children:
- 11cced6
- Parents:
- ab11ab1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/Cenum.tex
rab11ab1 rc4aca65 1 1 \chapter{C Enumeration in \texorpdfstring{\CFA}{Cforall}} 2 2 3 \CFA supports legacy C enumeration using the same syntax for backward scompatibility.3 \CFA supports legacy C enumeration using the same syntax for backward compatibility. 4 4 A C-style enumeration in \CFA is called a \newterm{C Enum}. 5 5 The semantics of the C Enum is mostly consistent with C with some restrictions. … … 15 15 enum E2 { @Fourth@, @Third@, @Second@, @First@ }; $\C{// same enumerator names}$ 16 16 \end{cfa} 17 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 17 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. 18 18 19 19 The \CFA type-system allows extensive overloading, including enumerators. 20 20 Hence, most ambiguities among C enumerators are implicitly resolved by the \CFA type system, possibly without any programmer knowledge of the conflict. 21 In addition, C Enum qualification is added, exactly like aggregate field -qualification, to disambiguate.21 In addition, C Enum qualification is added, exactly like aggregate field qualification, to disambiguate. 22 22 \VRef[Figure]{f:EnumeratorVisibility} shows how resolution, qualification, and casting are used to disambiguate situations for enumerations @E1@ and @E2@. 23 23 … … 66 66 As in Section~\ref{s:CVisibility}, 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. 67 67 68 A partially implemented extension to enumerator scoping is providing a combination of scoped and unscoped enumerators, using individual denotations, where @'^'@ means unscoped.69 \begin{cfa}70 enum E1 { @!@A, @^@B, C };71 enum E2 @!@ { @!@A, @^@B, C };72 \end{cfa}73 For @E1@, @A@ is scoped; @B@ and @C@ are unscoped.74 For @E2@, @A@ and @C@ are scoped; @B@ is unscoped.75 Finding a use case is important to justify completing this extension.76 77 68 78 69 \section{Type Safety} … … 80 71 As in Section~\ref{s:Usage}, C's implicit bidirectional conversion between enumeration and integral type raises a safety concern. 81 72 In \CFA, the conversion is changed to unidirectional: an enumeration can be implicitly converted into an integral type, with an associated @safe@ conversion cost. 82 Butan integral type cannot be implicitly converted into a C enumeration because the conversion cost is set to @infinity@.73 However, an integral type cannot be implicitly converted into a C enumeration because the conversion cost is set to @infinity@. 83 74 \begin{cfa} 84 75 enum Bird { Penguin, Robin, Eagle };
Note: See TracChangeset
for help on using the changeset viewer.