Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!sun-barr!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!swrinde!ucsd!ucbvax!bloom-beacon!vaxeline!bootsie!olson From: olson@bootsie.UUCP (Eric Olson) Newsgroups: comp.sys.mac.programmer Subject: Re: Casting in Think C Keywords: Casts ThinkC Message-ID: <40@bootsie.UUCP> Date: 7 Dec 90 02:33:19 GMT References: <6167@munnari.oz.au> <3028@skye.cs.ed.ac.uk> Reply-To: olson@endor.harvard.edu (Eric Olson) Organization: Lexington Software Design, Lexington, MA Lines: 55 In article <3028@skye.cs.ed.ac.uk> nick@lfcs.ed.ac.uk writes: > >As it should. I'm not sure what the argument to new() actually is/does, but >my guess is that it just provides a size (a la "sizeof") to determine how >much store to claim. > >gApplication is still a CApplication, and hence doesn't have an IEditApp() >method unless you cast it. > [The next line is not writen by nick -EKO] >> new is meant to "automatically assign a class to the newly created object" > >Now, I've never understood what this kind of thing means, ditto for Bless() >and all the rest. Presumably it does something automagical to the method >dispatcher. Anybody care to comment what "the class of an object" actually >means (as opposed to the static type of the object pointer)? > The object class types (like "CBorder") are a5-relative addresses, stored at the first longword of the Handle allocated by new(). a5 is subtracted off before the class type is stored by bless() or new(), and added in in the function below (so that comparisons will work right). You have to coerce the value returned by GetObjectClass() to (void *) before passing it to some other functions. As far as I know, functions can not return (void *) . /*============================================================================= GetObjectClass Get the type of an object. member(object, GetObjectClass(object)) always returns nonzero. =============================================================================*/ long GetObjectClass( CObject * obj) { asm { movea.l obj,a1 movea.l (a1),a1 ; <> move.w (a1),d0 ; D0.W = class ID ext.l d0 ; Sign extend the class ID add.l a5,d0 ; Add in a5 } } Cheers! -Eric -- Eric K. Olson, Editor, Prepare() NOTE: olson@bootsie.uucp will not work! Lexington Software Design Internet: olson@endor.harvard.edu 72A Lowell St., Lexington, MA 02173 Usenet: harvard!endor!olson (617) 863-9624 Bitnet: OLSON@HARVARD