Changeset 1dc6df0
 Timestamp:
 Apr 16, 2017, 9:45:31 AM (7 years ago)
 Branches:
 ADT, aaronthesis, armeh, astexperimental, cleanupdtors, deferred_resn, demangler, enum, forallpointerdecay, jacob/cs343translation, jenkinssandbox, master, newast, newastuniqueexpr, newenv, no_list, persistentindexer, pthreademulation, qualifiedEnum, resolvnew, with_gc
 Children:
 0aad606
 Parents:
 4635c79
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

doc/generic_types/generic_types.tex
r4635c79 r1dc6df0 257 257 For example, it is possible to write a typesafe \CFA wrapper @malloc@ based on the C @malloc@: 258 258 \begin{lstlisting} 259 forall( dtype T  sized(T) ) T * malloc( void ) { return (T *) (void *)malloc( (size_t)sizeof(T) ); }259 forall( dtype T  sized(T) ) T * malloc( void ) { return (T *)malloc( sizeof(T) ); } 260 260 int * ip = malloc(); $\C{// select type and size from lefthand side}$ 261 261 double * dp = malloc(); … … 505 505 Consider C's @div@ and @remquo@ functions, which return the quotient and remainder for a division of integer and floatingpoint values, respectively. 506 506 \begin{lstlisting} 507 typedef struct { int quo, rem; } div_t; 507 typedef struct { int quo, rem; } div_t; $\C{// from include stdlib.h}$ 508 508 div_t div( int num, int den ); 509 509 double remquo( double num, double den, int * quo ); … … 759 759 \begin{lstlisting} 760 760 int f( [int, double], double ); 761 forall(otype T, otype U  { T f( T, U, U ); }) 762 void g( T, U ); 761 forall(otype T, otype U  { T f( T, U, U ); }) void g( T, U ); 763 762 g( 5, 10.21 ); 764 763 \end{lstlisting} … … 767 766 Whenever a candidate's parameter structure does not exactly match the formal parameter's structure, a thunk is generated to specialize calls to the actual function: 768 767 \begin{lstlisting} 769 int _thunk( int _p0, double _p1, double _p2 ) { 770 return f( [_p0, _p1], _p2 ); 771 } 768 int _thunk( int _p0, double _p1, double _p2 ) { return f( [_p0, _p1], _p2 ); } 772 769 \end{lstlisting} 773 770 so the thunk provides flattening and structuring conversions to inferred functions, improving the compatibility of tuples and polymorphism.
Note: See TracChangeset
for help on using the changeset viewer.