wair92 wair92 - 1 year ago 112
C Question

Syntax in C language

What does this syntax in


EventEntry tTab[] =
{LEVEL, wLP0000FF00},
{0xFFFF, wL0000Ign}

I see just an array and something very similar to struct. So,
is an array of EventEntries, isnt it?

Answer Source

This is a declaration for an array of EventEntry objects, which are probably structs with a typedef (although they could also be arrays).

This syntax defines an array of two items. The fields of the initial item are initialized with {LEVEL, wLP0000FF00}, and the content of {0xFFFF, wL0000Ign} goes into the second element.

This is an old initialization syntax. New and improved one lets you designate the fields being initialized by name:

EventEntry tTab[] =
  {.field1 = LEVEL,  .field2 = wLP0000FF00},                         
  {.field1 = 0xFFFF, .field2 = wL0000Ign}