One embodiment of the present invention provides a system that detects violations
of type rules in a computer program. The system operates by locating a type casting
operation within the computer program, wherein the type casting operation involves
a first pointer and a second pointer. The system then checks the type casting operation
for a violation of a type rule. If a violation is detected, the system indicates
the violation. In one embodiment of the present invention, if the first pointer
is defined to be a structure pointer and the second pointer is not defined to be
a structure pointer, the system indicates a violation of a type rule. In one embodiment
of the present invention, if the first pointer is defined to point to a first structure
type and the second pointer is defined to point to a second structure type, the
system determines whether the first structure type and the second structure type
belong to the same alias group. If not, the system generates an error to indicate
a type violation.