[Tinyos Core WG] Adding fields to structs

Kevin Klues klueska at gmail.com
Thu Apr 5 00:05:29 PDT 2007


At the end of the meeting today (after David Gay left) we were
discussing if it would be possible to get nesc support for allowing
additional fields to be tacked on to the end of struct.

Such functionality would be useful in many different circumstances.
For the implementation of the cc2420 radio stack it could be used to
add additional fields based on the different layers that are added to
the stack.  It would also be useful for adding protocol specific
fields to a row in a neighbor table based solely on which components
have been included.

Potential syntax might be something like the following:

typedef struct my_struct {
  uint8_t my_field0;
  uint8_t my_field1;
} my_struct_t;

extend struct my_struct_t {
  uint8_t field2;
};

The primary advantage of this approach is that these extensions can
appear in places other than the original definition of the struct.
For example, the inclusion of the LinkLayerRetransmission layer for
the cc2420 stack could be accomplished by simply including a nesC
component in which the extended struct is declared (possibly in a
header file), rather than using the current approach where a
preprocessor variable needs to be defined and #ifdefs need to appear
throughout the definition of the cc2420_metadata_t struct in CC2420.h.

Is this something that could easily be added?  Is this something
people would find useful in other situations as well?

-- 
~Kevin


More information about the Tinyos-2.0wg mailing list