Ignore:
File:
1 edited

Legend:

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

    r566cc33 rf632117  
    1818\end{comment}
    1919
    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}.
     20Enumeration-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}.
    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} declaration binding a name to a constant literal/expression.
     26Classic Pascal has the \lstinline[language=Pascal]{const} aliasing 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 This mechanism is not an enumeration because there is no specific type (pseudo enumeration).
     31As stated, this 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 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.)
    218221\begin{c++}
    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,
     222const @auto@ one = 0 + 1;                               $\C{// static initialization}$
     223const @auto@ NIL = nullptr;
     224const @auto@ PI = 3.14159;
     225const @auto@ Plus = '+';
     226const @auto@ Fred = "Fred";
     227const @auto@ Mon = 0, Tue = Mon + 1, Wed = Tue + 1, Thu = Wed + 1, Fri = Thu + 1,
    225228                                Sat = Fri + 1, Sun = Sat + 1;
    226 int sa[Sun];
    227 const auto r = random();                                $\C{// dynamic initialization}$
    228 int da[r];                                                              $\C{// VLA}$
     229void foo() {
     230        const @auto@ r = random();                      $\C{// dynamic initialization}$
     231        int va[r];                                                      $\C{// VLA, auto scope only}$
     232}
    229233\end{c++}
    230234Statically initialized identifiers may appear in any constant-expression context, \eg @case@.
    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@).
     235Dynamically initialized identifiers may appear as array dimensions in @g++@, which allows variable-sized arrays.
     236Interestingly, global \CC @const@ declarations are implicitly marked @static@ (@r@, read-only local, rather than @R@, read-only external)
    233237\begin{c++}
    234238$\$$ nm test.o
    2352390000000000000018 @r@ Mon
    236240\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 
     241whereas C @const@ declarations without @static@ are marked @R@.
     242
     243The following non-backwards compatible changes are made \see{\cite[\S~7.2]{ANSI98:C++}}.
    241244\begin{cquote}
    242 7.2 Change: \CC objects of enumeration type can only be assigned values of the same enumeration type.
     245Change: \CC objects of enumeration type can only be assigned values of the same enumeration type.
    243246In C, objects of enumeration type can be assigned values of any integral type. \\
    244247Example:
     
    254257
    255258\begin{cquote}
    256 7.2 Change: In \CC, the type of an enumerator is its enumeration.
     259Change: In \CC, the type of an enumerator is its enumeration.
    257260In C, the type of an enumerator is @int@. \\
    258261Example:
     
    269272Taking the size of an enumerator is not a common C coding practice.
    270273\end{cquote}
    271 
    272274Hence, the values in a \CC enumeration can only be its enumerators (without a cast).
    273275While 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.