Listing 8: Combining use of assertions and defensive programming

int ObjectToInt( C_object* InObject )
{
  assert( InObject != NULL );
  if( InObject == NULL )
    return INT_MAX;

  int IntValue;
  switch( InObject->GetType() )
  {
    case kInteger:
    case KReal:
      IntValue = GetInteger( InObject );
      break;

    case kBoolean:
      IntValue = GetBoolean( InObject );
      break;

    case kPointer:
      IntValue = GetPointer( InObject );
      break;

    default:
      assert( "Invalid type of object" == NULL );
      IntValue = INT_MAX;
      break;
  }

  return IntValue;
}
//End of File