Chapter Contents

Previous

Next
Pointer Qualification Conversions, Casts, and Run-Time Type Identification

Pointer Qualification Conversions

Compilers for ANSI C and older C++ compilers allow implicit pointer qualification conversions such as int** to const int** that are not type-safe. For example:

void set_it( const int** target, const int* source )
{
   *target = source;
}

void test_it( const int* const_ptr )
{
   int* nonconst_ptr;

   // Get a non-const copy of const_ptr
   // without casts!!
   // The first argument uses the old unsafe
   // implicit conversion.
   set_it( &nonconst_ptr,
           const_ptr );

   *nonconst_ptr = 0; // assignment through
                      // const pointer
}

To avoid a similar problem with the C++ type system, the draft version of C++ allows only a subset of the implicit qualification conversions allowed in ANSI C. This subset can be summarized as follows:

For more information on implicit pointer qualification conversions, refer to section 4.4 of the ISO C++ draft.


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.