FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
June 01, 1997

C++

(Page 9 of 9)

June 1997/Being Assertive in C/C++/Listing 8

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
Previous Page | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK