Changeset 12d3187 for doc/rob_thesis/variadic.tex
- Timestamp:
- May 1, 2017, 1:39:55 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 2055098
- Parents:
- b3d70eba
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/rob_thesis/variadic.tex
rb3d70eba r12d3187 5 5 \section{Design Criteria} % TODO: better section name??? 6 6 C provides variadic functions through the manipulation of @va_list@ objects. 7 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} is needed to inform the function of the number of arguments and their types.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. 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 .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.}. 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} 154 155 Going one last step, it is possible to achieve full generality in \CFA, allowing the summation of arbitrary lists of summable types. 155 156 \begin{cfacode} … … 170 171 \end{cfacode} 171 172 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} 172 174 173 175 A notable limitation of this approach is that it heavily relies on recursive assertions. … … 226 228 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. 227 229 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.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. 229 231 This approach provides the type-safety of @new@ in \CC, without the need to specify the allocated type, thanks to return-type inference. 230 232
Note: See TracChangeset
for help on using the changeset viewer.