Changes in doc/rob_thesis/variadic.tex [12d3187:0111dc7]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/rob_thesis/variadic.tex
r12d3187 r0111dc7 5 5 \section{Design Criteria} % TODO: better section name??? 6 6 C provides variadic functions through the manipulation of @va_list@ objects. 7 In C, avariadic 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.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. 9 9 Two 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.}.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. 11 11 This required repetition is error prone, because it is easy for the user to add or remove arguments without updating the argument descriptor. 12 12 In addition, C requires the programmer to hard code all of the possible expected types. … … 152 152 That 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. 153 153 154 \begin{sloppypar}155 154 Going one last step, it is possible to achieve full generality in \CFA, allowing the summation of arbitrary lists of summable types. 156 155 \begin{cfacode} … … 171 170 \end{cfacode} 172 171 The \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}174 172 175 173 A notable limitation of this approach is that it heavily relies on recursive assertions. … … 228 226 In 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. 229 227 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.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. 231 229 This approach provides the type-safety of @new@ in \CC, without the need to specify the allocated type, thanks to return-type inference. 232 230
Note: See TracChangeset
for help on using the changeset viewer.