Next: , Previous: Templates, Up: Top


10 Typedefs

Type aliases or typedefs were not supported in CAST, but are worth mentioning as a new feature of HAC. Like in C, typedefs are a mechanism for giving user-defined names to an existing type. (TODO: discuss the benefits of style.) If one really wanted to use node and bool as the same type, one could write: ‘typedef bool node;’ and use node interchangeably with bool.

The real benefit is being able to bind definitions templates to new definitions that just forward template arguments to underlying types.

In the library channel.hac, we see the following example:

     template <pint N>
     defproc e1of (bool d[N], e) { ... }
     
     typedef	e1of<2> e1of2;

This declarations defines type e1of2 to be an alias to the complete type e1of<2>. In CAST, e1of(2) and e1of2 are different definitions and hence, could not be equivalent types. Connecting them required connecting their public port members, which was an inconvenience when mixing template types with non-template types. More common examples can be found in the library env.hac.