Chapter Contents |
Previous |
Next |
SAS/C C++ Development System User's Guide, Release 6.50 |
Release
6.50 of the SAS/C C++ Development System supports Run-Time Type Identification,
or RTTI. RTTI enables the compiler to automatically generate type information
for objects checked at run time. The
RTTI
option must be specified for each compilation unit to assure
that class objects constructed with functions defined in the unit have the
information required for dynamic type identification
by the
dynamic_cast
and
typeid()
operators. See Option Descriptions for more information
on the
RTTI
option. The
generated code will abort if the
dynamic_cast
or
typeid()
operators are applied to C++ class objects
with virtual functions which do not have RTTI information. This means it is
generally unsafe to have a program that uses
dynamic_cast
or
typeid()
but does not generate RTTI information in all of its compilation
units.
Compilation units that do not use
dynamic_cast
or
typeid()
can be compiled with the RTTI information. The resulting object
files can be safely linked into progams that do not use RTTI. The C++ library
is compiled this way. Note that dynamic type identification applies only to
C++ classes with virtual functions, so there is no compatibility issue with
non-C++ code.
ISO C++ specifies that certain erroneous uses of
dynamic_cast
and
typeid()
cause a C++ exception to be thrown. Release 6.50 of the SAS/C
C++ Development System does not support exceptions, so a mechanism corresponding
to default handling of an exception, with no user handler, is invoked for
these errors. Effectively, the
terminate()
operator is called,
which aborts the program by default. However, a handler can be specified by
set_terminate()
to perform
cleanup before terminating program execution. See typeinfo.h Header File for more information on these operators.
As an extension to ISO C++,
the run-time code for RTTI will detect when
dynamic type information is requested for an object that was not compiled
with the
RTTI
option.
In such cases, the
terminate()
mechanism is used to abort execution.
The
typeid()
operator
returns a reference to a statically allocated object. The destructor should
never be called for this object. Calling
typeid()
for the same type in different compilation units may produce
references to different objects. Always use operator
==
or operator
!=
to test for type equality.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © Tue Feb 10 12:11:23 EST 1998 by SAS Institute Inc., Cary, NC, USA. All rights reserved.