开发者

Strange struct declaration

I am familiar with structs and arrays in C, however I have no idea what is going on in the below code. The order for struct declaration is usually:

struct employee {
  char title;
  int year;
} mark;

Why are there 2 words after struct (below) as well as the [] bracket? As far as I know it is used as condition, action lookup table.

const struct act_tbl ActionTbl[] =
{
    {0, BUZZ | DISP 开发者_JAVA百科| A_ONCE},
    {0, BUZZ | DISP | A_ONCE},
};


The first part of your code,

struct employee {
  char title;
  int year;
} mark;

means "Define a struct called employee, then create an instance of it called mark." It's equivalent to the more verbose

struct employee {
  char title;
  int year;
};
struct employee mark;

The second part of your code,

const struct act_tbl ActionTbl[]={    {0, BUZZ|  DISP|  A_ONCE},
                                          {0, BUZZ|  DISP|  A_ONCE},

};

Means "create an array of objects of type struct act_tbl where the first act_tbl is initialized to {0, BUZZ| DISP| A_ONCE} and the second is initialized to {0, BUZZ| DISP| A_ONCE} as well." Without more knowledge about what act_tbl is, though, I don't think I can offer any more advice about why it's written the way it is.


It seems that:

struct act_tbl

Refers to a (struct) type that has been declared named act_tbl.

const struct act_tbl ActionTbl[]

Is initialising a 'const' form of that struct named ActionTbl[] (with the [] indicating the creation of an array)

{ {0, BUZZ| DISP| A_ONCE}, {0, BUZZ| DISP| A_ONCE}, };

Are the initialising parameters.


struct act_tbl is the type, and ActionTbl is the variable it declares.

A [] after the variable says that it is an array. Since it lacks an integer in between, the size of the array is determined by the number of initializers.


They're defining and initializing an array of act_tbl structures.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜