Listing 3: Checking data structure validity

enum
{
  kEnterOperation,
  kEnterMethod,
  kExitMethod,
  ...
  kDispatchGlue,
  kNUM_ENTRIES
};

class CodeGenerator
{
  ...
  static char* NamesTable[ kNUM_ENTRIES ];
  static void InitNames( void );
};

void CodeGenerator::InitNames( void )
{
  int i;

  for( i = 0; i < kNUM_ENTRIES; ++i )
    NamesTable[ i ] = NULL;

  NamesTable[ kEnterOperation ] = "EnterOperation";
  NamesTable[ kEnterMethod ]    = "EnterMethod";
  NamesTable[ kExitMethod ]     = "ExitMethod";
  ...
  NamesTable[ kDispatchGlue ]   = "DispatchGlue";

  for( i = 0; i < kNUM_ENTRIES; ++i )
    assert( NamesTable[ i] != NULL );
}
//End of File