user3053231
user3053231

Reputation:

Syntax in C language

What does this syntax in C mean?

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

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

Upvotes: 0

Views: 99

Answers (3)

Sergio
Sergio

Reputation: 8209

It means that tTab is an array of EventEntry, that by itself is a struct with at least two fields. And

{LEVEL, wLP0000FF00}

is initializer for tTab[0], and

{0xFFFF, wL0000Ign}

is initializer for tTab[1] Alternatively EventEntry may be an alias for an array with at least two elements.

Upvotes: 1

Peter
Peter

Reputation: 36637

Yes, tTab is an array of two EventEntrys.

{LEVEL, wLP0000FF00} initialises tTab[0] and the {0xFFFF, wL0000Ign} initialises tTab[1].

This assumes the values in LEVEL, wLP0000FF00, and wL0000Ign are valid values.

In this context, EventEntry might be a struct type or an array type (or a typedef for a struct or an array).

The types of LEVEL, wLP0000FF00, 0xFFFF, and wL0000IGn need to be compatible with (i.e. the same type or implicitly convertible to) the types of whatever fields or elements of EventEntry they are being used to initialise.

Upvotes: 1

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 727067

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}                                               
};

Upvotes: 1

Related Questions