[Tinyos-help] nesc question - declaring a variable that is dependent on a type parameter

David Gay dgay42 at gmail.com
Mon Jul 16 11:58:18 PDT 2007


On 7/16/07, Hugo Sousa <hcsousa at gmail.com> wrote:
> Let me clarify, let's say a certain generic component has a parameter
> "typedef width_t" (and an interface with a command that allows to pass
> along a "width_t variable")
>
> I want to perform some calculations on the variable, and store the
> results on other variables, but the type of those variables is width_t
> dependent
>
> for example, let's say that width_t is uint16_t
>
> then i'll want
>
> uint32_t mult;
> uint16_t sum;
> int16_t subtract;
>
> etc.
>
> if width_t is uint8_t it will be
>
> uint16_t mult;
> uint8_t sum;
> int8_t subtract;
>
> etc
>
> To simplify I can define some structs like
>  typedef struct { ... } store_result16_t
>  typedef struct { ... } store_result8_t
>
> but when I declared the struct variable to be used, is there a way to
> chose the one I want  depending on width_t?

No. Either pass all three types as arguments (and rely on the
programmer to get it right), or follow Michael's maximum precision
suggestion.

David Gay


More information about the Tinyos-help mailing list