Find greatly explain this structure

Category: C/C++ -> C Author: tareliang Date: 2005-06-24 17:17:01
 
tareliang
2005-06-24 17:17:01
typedef enum {
var_null = 0,
var_double,
var_string
} variant_type ;
typedef char STRING [128];
typedef struct {
variant_type type;
union {
double i;
STRING s;
};
} VARIANT ;

just saw Mo who sent me this structure ... directly read the ... Weighs
xiaowaer0
2005-06-24 17:30:42
can not read this, take a look at structures and unions.
typedef char STRING [128]
That STRING a equivalent char a [128]
as417177608
2005-06-24 17:43:31
VARIANT structure type which has two members, one is an enumeration type variant_type variable type, the other is an anonymous union, one of the members of this anonymous union s is an array type char [128].
yuhao136
2005-06-24 17:58:36


er er, go back and take a look typedef, structures, and unions
sww5505
2005-06-24 18:06:21
var_string and STRING relationship you have?
dadappt99
2005-06-24 18:21:25
okay, var_string enum is a member, STRING is a char [128]
bubufanfan
2005-06-24 18:24:08

code here shows no relationship.
This is the complete code?
beiguiyan007
2005-06-24 18:33:07

no var_string is a constant for the 2
STRING is a macro definition is char [128]
hulihua520
2005-06-24 18:40:17
typedef enum
{
var_null = 0,
var_double,
var_string
} variant_type; / / declare an enumerated data type

typedef char STRING [128 ]; / / STRING symbols instead of 128 bytes with a wide array of bytes
; / / ie STRING a; <=> char a [128];

typedef struct
{
; variant_type type; / / enumeration should be used to indicate the following data is of type double or string type
;
union / / union, but looks like a union to give a name, right? never used this kind of thing, is not very clear.
{
double i;
STRING s;
};
} VARIANT;

swe05027
2005-06-24 18:47:02
Oh, upstairs upstairs to say quite clearly
LauSonghui
2005-06-24 19:02:00
learn, huh, huh!
suihongyuooooo
2005-06-24 19:19:15
slowly, clearly set out to understand the structure of the
kelele2008
2005-06-24 19:32:35
is the use of typedef enum type Commonwealth. Look book they all clear.
fanmeng19891
2005-06-24 19:43:47
to learn from it.
wukaihuaw
2005-06-24 19:58:05
almost, knot paste it
zhwsmile
2005-06-24 20:14:38
enum is an enumeration, the initial value 0
thinkhigher
2005-06-24 20:31:37


example: enum color {red, blue, green, white, black};
Description: 1.color is an enumeration type name, it is not a variable name, it does not account for memory Space
2. in memory, the compiler will enumerate the types of variables as integer constants defined
The compiler will assign the value 0 enumerate the first value in the list, the one assigned to
value of two, and so on.
3. define an enumerated type, you can define the enumerated type variable, the variable
values ​​can only be defined enumerated type values ​​specified. Such as: color paint = green (ok)
color paint = 200 (error)