Insure++ Reference - BAD_CAST
Porting code between differing machine architectures
can be difficult for many reasons. A particularly tricky problem occurs
when the sizes of data objects, particularly pointers, differ from that for
which the software was created. This error occurs when a pointer is cast to
a type with fewer bits, causing information to be lost, and is designed to
help in porting codes to architectures where, for example, pointers and
integers are of different lengths.
Note that compilers will often catch this problem unless the user
has "carefully" added the appropriate typecast to make the
conversion "safe".
The following code shows a pointer being copied to a variable too
small to hold all its bits.
1: /*
2: * File: badcast.c
3: */
4: main()
5: {
6: char q, *p;
7:
8: p = "Testing";
9: q = (char)p;
10: return 0;
11: }
1. [badcast.c:9] **BAD_CAST**
2. Cast of pointer loses precision: (char) p
>> q = (char) p;
- Source line at which the problem was detected.
- Description of the problem and the expression that is in error.
This error normally indicates a significant portability problem
that should be corrected by using a different type to save the pointer
expression. In ANSI C the type void * will always
be large enough to hold a pointer value.
ALLOC_CONFLICT
BAD_DECL
|