Chapter Contents |
Previous |
Next |
Pointer Qualification Conversions, Casts, and Run-Time Type Identification |
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 }
const
. For example, an
int**
pointer cannot be implicitly converted
to
const int**
but it can
be implicitly converted to
const int* const *
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.