On Mon, Jul 08, 2002 at 07:57:08PM +0530, Dinesh Kumar wrote:
> Hi ,
> 
> I'm implementing a Variant and declaring  a self referential structure in
> CodeWarrior as below
> I'm facing the following error ,pl help !
> 
> 
> 
> //struct Variant;
> 
> struct  Variant
> {
>     Uint8 vt;
>     char stringVal[256];
>     UInt8  byteVal;
>     UInt8 *byteArray;
>     Boolean boolVal;
>     UInt32 intVal;
>     struct tagVARIANT  varVal;   <<----ERROR :  Illegal Use of Incomplete
> Struct/Union/Class  Variant
> };

I think you are trying to do:

  struct Variant
  {
      Uint8           vt;
      char            stringVal[256];
      UInt8           byteVal;
      UInt8          *byteArray;
      Boolean         boolVal;
      UInt32          intVal;
      struct Variant *varVal;
  };

where you store a _pointer_ to the struct, not the struct itself
Otherwise, how much space will use the structure? (Hint: you can't
have structures requiring infinite space :)

But the meaning of what you are trying to do is not clear, and from
the definition above, it seems you are trying to store only one instance
of a datatype at a time. If this is the case, you should use a union:

typedef enum vartype_tag { vt_string, vt_byte, vt_bytearray, vt_bool, vt_int } vartype;

struct variant
{
    vartype vt;
    union
    {
       char      stringVal[256];
       UInt8     byteVal;
       UInt8    *byteArray;
       Boolean   boolVal;
       UInt32    intVal;
    } v;
};

Marco

-- 
========================================================================
Marco Pantaleoni                                  [EMAIL PROTECTED]
Padova, Italy                                              [EMAIL PROTECTED]
elastiC language developer                   http://www.elasticworld.org


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to