Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/rob_thesis/variadic.tex

    r12d3187 r0111dc7  
    55\section{Design Criteria} % TODO: better section name???
    66C provides variadic functions through the manipulation of @va_list@ objects.
    7 In C, 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} or \emph{sentinel value} is needed to inform the function of the number of arguments and their types.
     7A 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} 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 \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.}.
     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.
    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}
    155154Going one last step, it is possible to achieve full generality in \CFA, allowing the summation of arbitrary lists of summable types.
    156155\begin{cfacode}
     
    171170\end{cfacode}
    172171The \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}
    174172
    175173A notable limitation of this approach is that it heavily relies on recursive assertions.
     
    228226In 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.
    229227
    230 The @new@ function provides the combination of polymorphic @malloc@ with a constructor call, so that it becomes impossible to forget to construct dynamically-allocated objects.
     228The @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.
    231229This approach provides the type-safety of @new@ in \CC, without the need to specify the allocated type, thanks to return-type inference.
    232230
Note: See TracChangeset for help on using the changeset viewer.