HI,

 

I understand that If I have multiple struct types,  I would have to have
multiple copies of code to operate on them. I was just hoping that the
compiler would do the work for me if I made the component generic,
rather than me maintaining multiple copies  of   almost identical  code
. My   understanding of generic modules was that they  make the same
module work with different data types( built-in and  user-defined data
types  )  . 

If a data type was type defined in a module , I assumed  that you could
access it like a regular struct anywhere in the module. I now understand
that it is  not the case.

 

The only solution, I see for my scenario is to have multiple
(identical)modules each accepting one struct type as an argument .



 

Thanks,

Lewis

 

Hi Eric,

I have multiple structures with a few common elements. The operations to
be performed  on these elements are similar across all structs. The
generic module seemed to be an easy way to avoid duplicating the code

 

It doesn't actually avoid duplicating the code rather it replicates the
code.  Meaning every time you instantiate the generic module the entire
module is replicated in the resultant output (app.c).

 

Generic modules should get used when you are doing something that is
generically the same but the details are somewhat different.

 

What you are trying to do is the details are the same and you want to
use common code.   That isn't what generic is for.

 

>From the TinyOS Programming manual...

Then nesC generates two copies of the VirtualizeTimerC's code. It does
this because different instances of Virtu- alizeTimerC might have
different types and different constants.

 

VirtualizeTimerC is generic....

 

  

 

        for each struct, since the struct would be defined (typedef
type) in each module , I expected the compiler would be aware of the
data type.
        Thanks,

        Lewis

         

        From: Eric Decker [mailto:cire...@gmail.com] 
        Sent: Monday, April 23, 2012 11:23 PM
        To: Oldrine Lewis
        Cc: tinyos-help@millennium.berkeley.edu
        Subject: Re: [Tinyos-help] Question regarding generic components

         

         

        On Mon, Apr 23, 2012 at 7:23 PM, Oldrine Lewis
<ole...@sutron.com> wrote:

        Hi Eric,

        I wanted to make the module (MyModuleM  ) a generic module so
that it can handle different structs. 

         

        Using a generic module is not exactly a good idea.

         

        The way generic works is it replicates code.   Essentially the
code is duplicated for each instance (i.e. new invocation).

         

        So if you have common pieces of a structure then you should
probably access it using a non-generic access module.  That way

        you can still accomplish the abstraction without duplicating the
code.

         

                The different structs all have  some identical members.
MyModuleM  will perform some generic operations 

         

        calling these generic operations is fairly confusing.

         

        eric

         

         

                on these common members 

                Thanks,

                Lewis

                 

                 

                From: Eric Decker [mailto:cire...@gmail.com] 
                Sent: Monday, April 23, 2012 10:13 PM
                To: Oldrine Lewis
                Cc: tinyos-help@millennium.berkeley.edu
                Subject: Re: [Tinyos-help] Question regarding generic
components

                 

                 

                On Mon, Apr 23, 2012 at 7:05 PM, Oldrine Lewis
<ole...@sutron.com> wrote:

                Hi,

                 

                Can I access the members in a user defined type inside a
generic module? 

                 

                typedef struct

                {

                     uint8_t m_count;

                }MyStruct;

                 

                 

                 

                generic module MyModuleM(typedef type)

                {

                     provides interface MyInterface;

                }

                implementation

                {

                     command void MyInterface.TestStructAccess(type* t)

                 

                try 

                 

                     command void MyInterface.TestStructAccess(MyStruct*
t)

                 

                 

                        {

                             t->m_count++;//I get an error here 

                        }

                        }

                         

                         

                        Thanks,

                        Lewis

                         

                        
                        _______________________________________________
                        Tinyos-help mailing list
                        Tinyos-help@millennium.berkeley.edu
        
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

                
                
                

                 

                -- 
                Eric B. Decker
                Senior (over 50 :-) Researcher

        
        
        

         

        -- 
        Eric B. Decker
        Senior (over 50 :-) Researcher





 

-- 
Eric B. Decker
Senior (over 50 :-) Researcher



_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to