- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/relatedwork.tex
r566cc33 rf632117 18 18 \end{comment} 19 19 20 Enumeration types exist in many popular programming languages, both past and present, \eg Pascal~\cite{Pascal}, Ada~\cite{Ada}, \Csharp~\cite{Csharp}, OCaml~\cite{OCaml} \CC, Go~\cite{Go}, Java~\cite{Java}, Modula-3~\cite{Modula-3}, Rust~\cite{Rust}, Swift~\cite{Swift}, Python~\cite{Python}.20 Enumeration-like features exist in many popular programming languages, both past and present, \eg Pascal~\cite{Pascal}, Ada~\cite{Ada}, \Csharp~\cite{Csharp}, OCaml~\cite{OCaml} \CC, Go~\cite{Go}, Haskell~\cite{Haskell}, Java~\cite{Java}, Modula-3~\cite{Modula-3}, Rust~\cite{Rust}, Swift~\cite{Swift}, Python~\cite{Python}. 21 21 Among theses languages, there are a large set of overlapping features, but each language has its own unique extensions and restrictions. 22 22 … … 24 24 \label{s:Pascal} 25 25 26 Classic Pascal has the \lstinline[language= pascal]{const}declaration binding a name to a constant literal/expression.26 Classic Pascal has the \lstinline[language=Pascal]{const} aliasing declaration binding a name to a constant literal/expression. 27 27 \begin{pascal} 28 28 const one = 0 + 1; Vowels = set of (A,E,I,O,U); NULL = NIL; 29 29 PI = 3.14159; Plus = '+'; Fred = 'Fred'; 30 30 \end{pascal} 31 This mechanism is not an enumeration because there is no specific type (pseudo enumeration).31 As stated, this mechanism is not an enumeration because there is no specific type (pseudo enumeration). 32 32 Hence, there is no notion of a (possibly ordered) set, modulo the \lstinline[language=pascal]{set of} type. 33 33 The type of each constant name (enumerator) is inferred from the constant-expression type. … … 139 139 Ops : array( 0..3 ) of Operator; 140 140 Ops := @"+-*/"@; -- string assignment to array elements 141 Ops := @"+-" & "*/"@; -- string concatenation and assignment141 Ops := "+-" @&@ "*/"; -- string concatenation and assignment 142 142 \end{ada} 143 143 Ada's @Character@ type is defined as a character enumeration across all Latin-1 characters. … … 215 215 \label{s:C++RelatedWork} 216 216 217 \CC has the equivalent of Pascal typed @const@ declarations \see{\VRef{s:Pascal}}, with static and dynamic initialization. 217 \CC enumeration is largely backwards compatible with C, so it inherited C's enumerations with some modifications and additions. 218 219 \CC has aliasing using @const@ declarations, like C \see{\VRef{s:Cconst}}, with type inferencing, plus static/dynamic initialization. 220 (Note, a \CC @constexpr@ declaration is the same @const@ with the restriction that the initialization is a compile-time expression.) 218 221 \begin{c++} 219 const auto one = 0 + 1;$\C{// static initialization}$220 const auto NULL = nullptr;221 const autoPI = 3.14159;222 const autoPlus = '+';223 const autoFred = "Fred";224 const autoMon = 0, Tue = Mon + 1, Wed = Tue + 1, Thu = Wed + 1, Fri = Thu + 1,222 const @auto@ one = 0 + 1; $\C{// static initialization}$ 223 const @auto@ NIL = nullptr; 224 const @auto@ PI = 3.14159; 225 const @auto@ Plus = '+'; 226 const @auto@ Fred = "Fred"; 227 const @auto@ Mon = 0, Tue = Mon + 1, Wed = Tue + 1, Thu = Wed + 1, Fri = Thu + 1, 225 228 Sat = Fri + 1, Sun = Sat + 1; 226 int sa[Sun]; 227 const auto r = random(); $\C{// dynamic initialization}$ 228 int da[r]; $\C{// VLA}$ 229 void foo() { 230 const @auto@ r = random(); $\C{// dynamic initialization}$ 231 int va[r]; $\C{// VLA, auto scope only}$ 232 } 229 233 \end{c++} 230 234 Statically initialized identifiers may appear in any constant-expression context, \eg @case@. 231 Dynamically in tialized identifiers may appear as array dimensions in @g++@, which allows variable-sized arrays.232 Interestingly, global \CC @const@ declarations are implicitly marked @static@ (@r@ rather than @R@).235 Dynamically initialized identifiers may appear as array dimensions in @g++@, which allows variable-sized arrays. 236 Interestingly, global \CC @const@ declarations are implicitly marked @static@ (@r@, read-only local, rather than @R@, read-only external) 233 237 \begin{c++} 234 238 $\$$ nm test.o 235 239 0000000000000018 @r@ Mon 236 240 \end{c++} 237 238 \CC enumeration is largely backwards compatible with C, so it inherited C's enumerations. 239 However, the following non-backwards compatible changes are made. 240 241 whereas C @const@ declarations without @static@ are marked @R@. 242 243 The following non-backwards compatible changes are made \see{\cite[\S~7.2]{ANSI98:C++}}. 241 244 \begin{cquote} 242 7.2Change: \CC objects of enumeration type can only be assigned values of the same enumeration type.245 Change: \CC objects of enumeration type can only be assigned values of the same enumeration type. 243 246 In C, objects of enumeration type can be assigned values of any integral type. \\ 244 247 Example: … … 254 257 255 258 \begin{cquote} 256 7.2Change: In \CC, the type of an enumerator is its enumeration.259 Change: In \CC, the type of an enumerator is its enumeration. 257 260 In C, the type of an enumerator is @int@. \\ 258 261 Example: … … 269 272 Taking the size of an enumerator is not a common C coding practice. 270 273 \end{cquote} 271 272 274 Hence, the values in a \CC enumeration can only be its enumerators (without a cast). 273 275 While the storage size of an enumerator is up to the compiler, there is still an implicit cast to @int@.
Note: See TracChangeset
for help on using the changeset viewer.