2

How is the last item in myarray valid? Supposedly this is an "empty-terminated list". This is C code.

typedef struct sFoo
{
    char *a;
    char *b;
} SFOO;

static SFOO my_sfoo_array[] =
    {
        { 0x1000, 0x2000 },
        { 0x3000, 0x4000 },
        { }        /* what?! */
    };

Are the missing structure elements automatically supplied as 0, so that the last entry { } is really {0, 0}?

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
MPW
  • 329
  • 2
  • 13

1 Answers1

0

This is not a valid C initialization

static SFOO my_sfoo_array[] =
    {
        { 0x1000, 0x2000 },
        { 0x3000, 0x4000 },
        { }        /* what?! */
    };

C does not allow empty braces.

In C++ it means value initialization.

So in C it would be correctly to write

static SFOO my_sfoo_array[3] =
    {
        { 0x1000, 0x2000 },
        { 0x3000, 0x4000 },
    };

In this case the members of the third element will be initialized by null-pointers. The initializer in C is defined like

initializer:
    assignment-expression
    { initializer-list }
    { initializer-list , }

as you can see the initializer-list is not optional.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335