Getting started

James J. Besemer jb at cascade-sys.com
Thu Sep 26 02:19:06 EDT 2002


Brian Quinlan wrote:

>>Some use "weak typing" to mean any type system where the typing can be
>>foiled by casts;
>>    
>>
>
>What does "foiled by" mean in this context?
>
Bypassed or otherwise defeated.  A "cast" in C or C++ is a way to 
override the type system.  Sometimes this is meaningful and useful but 
it also can result in catestrophic type errors.

Types are otherwise pretty secure in C++ except the "cast" mechanism 
"foils" the type system and thus allows type errors to occur.

An earlier example was:

    CEdit* edit = (CEdit*)GetDlgItem( ID_EDIT );

This fetches a pointer to user interface "dialog item" from the existing 
GUI.  Such objects may be of different types.  GetDlgItem() returns a 
pointer to a generic CWnd type, which is the super class to all the 
possible window objects..  The (CEdit*) is a cast says to convert the 
pointer from whatever it may have been (one for a generic windows 
object) to specifically be an Edit Box object.  If all goes well then 
this works just fine.  However, if the dialog item happens NOT to be an 
edit box, say if it was a list box instead, then the resulting object 
pointer would point to the wrong object type and likely result in a 
fatal error when list box operations are applied to the edit box object.

Regards

--jb

-- 
James J. Besemer		503-280-0838 voice
2727 NE Skidmore St.		503-280-0375 fax
Portland, Oregon 97211-6557	mailto:jb at cascade-sys.com
				http://cascade-sys.com	








More information about the Python-list mailing list