C quiz για τους καλοκαιρινούς μήνες

V13 v13 at v13.gr
Mon Jul 18 15:52:04 EEST 2011


On Monday 18 of July 2011, Christos Houtouridis wrote:
> typedef struct MenuObject* MenuObject_pt;
> typedef void (*MenuFunc_pt) (void);
> 
> typedef union node
> {
>    MenuFunc_pt    task;
>    MenuObject_pt  menu;
> }Node_t;
> 
> typedef struct MenuObject
> {
>    Caption_t      cap;
>    Node_t         link;
>    int8_t         isMenu;
> }MenuObject_t;

[...]

> const MenuObject_t Menu_Main[] =
> {
>   {"",0,0},
>   {">A ",  task_A,      0},
>   {"sub",  Menu_Sub,    1},
>   {"ESC",  UI_MenuBack, 0},
>   {0,0,0}
> };

Mallon thes ayto:

const MenuObject_t Menu_Main[] =
{
  [...]
  {"sub",  .link.menu=(MenuObject_pt)Menu_Sub,    1},
  [...]
};

Xoris to .link.menu prospathei na kanei initialization me basi to proto 
stoixeio toy union kai exo thn entyposi pos ayto einai standard.

Xoris to (MenuObject_pt) isos na gkriniaksei giati to (MenuObject_t *) einai 
diaforetikos typos apo to MenuObject_pt (esto kai an einai symbata / ta idia 
sth praksi).

An den doylevei to .link.menu tote dokimase:

const MenuObject_t Menu_Main[] =
{
  [...]
  {"sub",  {.menu=(MenuObject_pt)Menu_Sub},    1},
  [...]
};


More information about the Linux-greek-users mailing list