Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/rob_thesis/variadic.tex

    r0111dc7 r12d3187  
    55\section{Design Criteria} % TODO: better section name???
    66C provides variadic functions through the manipulation of @va_list@ objects.
    7 A variadic function is one which contains at least one parameter, followed by @...@ as the last token in the parameter list.
    8 In particular, some form of \emph{argument descriptor} is needed to inform the function of the number of arguments and their types.
     7In C, a variadic function is one which contains at least one parameter, followed by @...@ as the last token in the parameter list.
     8In particular, some form of \emph{argument descriptor} or \emph{sentinel value} is needed to inform the function of the number of arguments and their types.
    99Two common argument descriptors are format strings or counter parameters.
    10 It is important to note that both of these mechanisms are inherently redundant, because they require the user to explicitly specify information that the compiler already knows.
     10It is important to note that both of these mechanisms are inherently redundant, because they require the user to explicitly specify information that the compiler already knows \footnote{While format specifiers can convey some information the compiler does not know, such as whether to print a number in decimal or hexadecimal, the number of arguments is wholly redundant.}.
    1111This required repetition is error prone, because it is easy for the user to add or remove arguments without updating the argument descriptor.
    1212In addition, C requires the programmer to hard code all of the possible expected types.
     
    152152That is to say, the programmer who writes @sum@ does not need full program knowledge of every possible data type, unlike what is necessary to write an equivalent function using the standard C mechanisms.
    153153
     154\begin{sloppypar}
    154155Going one last step, it is possible to achieve full generality in \CFA, allowing the summation of arbitrary lists of summable types.
    155156\begin{cfacode}
     
    170171\end{cfacode}
    171172The \CFA translator requires adding explicit @double ?+?(int, double)@ and @double ?+?(double, int)@ functions for this call to work, since implicit conversions are not supported for assertions.
     173\end{sloppypar}
    172174
    173175A notable limitation of this approach is that it heavily relies on recursive assertions.
     
    226228In the call to @new@, @Array@ is selected to match @T@, and @Params@ is expanded to match @[int, int, int, int]@. To satisfy the assertions, a constructor with an interface compatible with @void ?{}(Array *, int, int, int)@ must exist in the current scope.
    227229
    228 The @new@ function provides the combination of type-safe @malloc@ with a constructor call, so that it becomes impossible to forget to construct dynamically-allocated objects.
     230The @new@ function provides the combination of polymorphic @malloc@ with a constructor call, so that it becomes impossible to forget to construct dynamically-allocated objects.
    229231This approach provides the type-safety of @new@ in \CC, without the need to specify the allocated type, thanks to return-type inference.
    230232
Note: See TracChangeset for help on using the changeset viewer.