Ignore:
File:
1 edited

Legend:

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

    rf632117 r566cc33  
    1818\end{comment}
    1919
    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}.
     20Enumeration 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}.
    2121Among theses languages, there are a large set of overlapping features, but each language has its own unique extensions and restrictions.
    2222
     
    2424\label{s:Pascal}
    2525
    26 Classic Pascal has the \lstinline[language=Pascal]{const} aliasing declaration binding a name to a constant literal/expression.
     26Classic Pascal has the \lstinline[language=pascal]{const} declaration binding a name to a constant literal/expression.
    2727\begin{pascal}
    2828const one = 0 + 1;   Vowels = set of (A,E,I,O,U);   NULL = NIL;
    2929                 PI = 3.14159;   Plus = '+';   Fred = 'Fred';
    3030\end{pascal}
    31 As stated, this mechanism is not an enumeration because there is no specific type (pseudo enumeration).
     31This mechanism is not an enumeration because there is no specific type (pseudo enumeration).
    3232Hence, there is no notion of a (possibly ordered) set, modulo the \lstinline[language=pascal]{set of} type.
    3333The type of each constant name (enumerator) is inferred from the constant-expression type.
     
    139139Ops : array( 0..3 ) of Operator;
    140140Ops := @"+-*/"@;            -- string assignment to array elements
    141 Ops := "+-" @&@ "*/";   -- string concatenation and assignment
     141Ops := @"+-" & "*/"@;   -- string concatenation and assignment
    142142\end{ada}
    143143Ada's @Character@ type is defined as a character enumeration across all Latin-1 characters.
     
    215215\label{s:C++RelatedWork}
    216216
    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.
    221218\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,
     219const auto one = 0 + 1;                                 $\C{// static initialization}$
     220const auto NULL = nullptr;
     221const auto PI = 3.14159;
     222const auto Plus = '+';
     223const auto Fred = "Fred";
     224const auto Mon = 0, Tue = Mon + 1, Wed = Tue + 1, Thu = Wed + 1, Fri = Thu + 1,
    228225                                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 }
     226int sa[Sun];
     227const auto r = random();                                $\C{// dynamic initialization}$
     228int da[r];                                                              $\C{// VLA}$
    233229\end{c++}
    234230Statically initialized identifiers may appear in any constant-expression context, \eg @case@.
    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)
     231Dynamically intialized identifiers may appear as array dimensions in @g++@, which allows variable-sized arrays.
     232Interestingly, global \CC @const@ declarations are implicitly marked @static@ (@r@ rather than @R@).
    237233\begin{c++}
    238234$\$$ nm test.o
    2392350000000000000018 @r@ Mon
    240236\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.
     239However, the following non-backwards compatible changes are made.
     240
    244241\begin{cquote}
    245 Change: \CC objects of enumeration type can only be assigned values of the same enumeration type.
     2427.2 Change: \CC objects of enumeration type can only be assigned values of the same enumeration type.
    246243In C, objects of enumeration type can be assigned values of any integral type. \\
    247244Example:
     
    257254
    258255\begin{cquote}
    259 Change: In \CC, the type of an enumerator is its enumeration.
     2567.2 Change: In \CC, the type of an enumerator is its enumeration.
    260257In C, the type of an enumerator is @int@. \\
    261258Example:
     
    272269Taking the size of an enumerator is not a common C coding practice.
    273270\end{cquote}
     271
    274272Hence, the values in a \CC enumeration can only be its enumerators (without a cast).
    275273While 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.