assuming I have an object similar to this one:
struct MenuDef
{
int titleResourceId;
struct MenuItemDef {
char* name;
int value;
SomeFunctionPtr someFactory;
} menuItems[10];
};
That is initialized like this:
const MenuDef m = {
1,
{
{
"zero",
0,
(SomeFunctionPtr) & MenuButton::factory,
},
{
"one",
1,
(SomeFunctionPtr) & MenuButton::factory,
},
{
"two",
2,
(SomeFunctionPtr) & MenuButton::factory,
},
}
};
Is it safe to assume that m.menuItems[3].someFactory == 0 ?
for example in a loop like this:
for ( int i = 0; m.menuItems[i].someFactory != 0; ++i)
or do I have to insert a last element to mark the array end by hand just to be safe?
...
{
"two",
2,
(SomeFunctionPtr) & MenuButton::factory,
},
{
"",
0,
(SomeFunctionPtr) 0,
},
...
I believe it is safe according to 8.5.1/7 :
As a reminder :