- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/relatedwork.tex
rf632117 r566cc33 18 18 \end{comment} 19 19 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}.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}. 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} aliasingdeclaration binding a name to a constant literal/expression.26 Classic Pascal has the \lstinline[language=pascal]{const} 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 As stated, this mechanism is not an enumeration because there is no specific type (pseudo enumeration).31 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 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.) 217 \CC has the equivalent of Pascal typed @const@ declarations \see{\VRef{s:Pascal}}, with static and dynamic initialization. 221 218 \begin{c++} 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,219 const auto one = 0 + 1; $\C{// static initialization}$ 220 const auto NULL = nullptr; 221 const auto PI = 3.14159; 222 const auto Plus = '+'; 223 const auto Fred = "Fred"; 224 const auto Mon = 0, Tue = Mon + 1, Wed = Tue + 1, Thu = Wed + 1, Fri = Thu + 1, 228 225 Sat = Fri + 1, Sun = Sat + 1; 229 void foo() { 230 const @auto@ r = random(); $\C{// dynamic initialization}$ 231 int va[r]; $\C{// VLA, auto scope only}$ 232 } 226 int sa[Sun]; 227 const auto r = random(); $\C{// dynamic initialization}$ 228 int da[r]; $\C{// VLA}$ 233 229 \end{c++} 234 230 Statically initialized identifiers may appear in any constant-expression context, \eg @case@. 235 Dynamically in itialized 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)231 Dynamically intialized 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@). 237 233 \begin{c++} 238 234 $\$$ nm test.o 239 235 0000000000000018 @r@ Mon 240 236 \end{c++} 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++}}. 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 244 241 \begin{cquote} 245 Change: \CC objects of enumeration type can only be assigned values of the same enumeration type.242 7.2 Change: \CC objects of enumeration type can only be assigned values of the same enumeration type. 246 243 In C, objects of enumeration type can be assigned values of any integral type. \\ 247 244 Example: … … 257 254 258 255 \begin{cquote} 259 Change: In \CC, the type of an enumerator is its enumeration.256 7.2 Change: In \CC, the type of an enumerator is its enumeration. 260 257 In C, the type of an enumerator is @int@. \\ 261 258 Example: … … 272 269 Taking the size of an enumerator is not a common C coding practice. 273 270 \end{cquote} 271 274 272 Hence, the values in a \CC enumeration can only be its enumerators (without a cast). 275 273 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.