You are right about
    typedef struct { int16_t var; } MateValueVariable;
being functionally equivalent to
    typedef int16_t MateValueVariable;

However the usage would be a bit different.
For the first you would do:
    MateValueVariable x;
    x.val = NNN;
and the second:
    MateValueVariable x;
    x = NNN;

Since there are two examples of seeming redundancy, and they have
the same member name "val", someone may be trying to imitate Object
Disoriented overloading or something. You'd have to go look at
the use in the code to see if there was rhyme or reason. One reason
would be that using a struct allows for future expansion of ...Variable
without having to modify existing code.

MS


Supasate Choochaisri wrote:
Hi all,

I'm not quite familiar with C language, so I doubt about the following codes in Mate (TinyOS-VM) :

1: typedef struct {
2:   int16_t var;
3: } MateValueVariable;
4: 5: typedef struct {

6:   uint8_t type;
7:   uint8_t size;
8:   int16_t entries[MATE_BUF_LEN];
9: } MateDataBuffer;
10: 11: typedef struct {
12:   MateDataBuffer* var;
13: } MateBufferVariable;
14: 15: typedef struct {

16:   uint8_t type;
17:   union {
18:     MateValueVariable value;
19:     MateBufferVariable buffer;
20:   };
21: } MateStackVariable;


Line 1-3, compare to "typedef int16_t MateValueVariable", how difference is it?

Line 11-13, why do we have to use this struct? why not just change line 9 to MateBufferVariable and delete line 11-13?

Thanks in advance,

Supasate


------------------------------------------------------------------------

_______________________________________________
Tinyos-help mailing list
Tinyos-help@Millennium.Berkeley.EDU
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
Tinyos-help@Millennium.Berkeley.EDU
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to