Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!bbn.com!nic!chaos.cs.brandeis.edu!chaos!phils From: phils@chaos.cs.brandeis.edu (Phil Shapiro) Newsgroups: comp.sys.mac.programmer Subject: Re: Casting in Think C Message-ID: Date: 11 Dec 90 15:35:46 GMT References: <6167@munnari.oz.au> <3028@skye.cs.ed.ac.uk> <1990Dec10.174536.17002@dhw68k.cts.com> Sender: phils@chaos.cs.brandeis.edu (Phil Shapiro) Organization: Symantec Corp. Lines: 36 In-Reply-To: emmayche@dhw68k.cts.com's message of 10 Dec 90 17:45:36 GMT In article <1990Dec10.174536.17002@dhw68k.cts.com> emmayche@dhw68k.cts.com (Mark Hartman) writes: [ ... I said that objects are uniquely identified at compile time by "Class ID"s ... ] Understanding that these "Class ID" numbers will vary from application to application (and even from compile to compile of the same application), they would still come in very handy for a "save state" kind of use. How is it possible to access these Class ID numbers and relate them to a class so that I can read an instance back in from a file and Bless() it to the proper class? The easy answer is to use the two classes that have been written already to do this. There is one for Pascal called "Instance.p" by Bill Stackhouse, and a C version (based on Bill Stackhouse's code) called "CInstance.c" by Sven Axelsson. The C version is part of a larger package from Sven Axelsson that has many examples of Think C code. You should be able to find these files at your usual ftp archive. The hard answer is that the Class ID is a 2 byte integer value stored at the beginning of the object. So, if you have an indirect object "o", you can use "*(short *)(*o)" in C. At run time, you can use this information to relate a object to its class, that's how member() works. Of course, the location and size of the Class ID may change in future versions of the Think compilers. -phil -- Phil Shapiro Technical Support Analyst Language Products Group Symantec Corporation Internet: phils@chaos.cs.brandeis.edu -- Phil Shapiro Technical Support Analyst Language Products Group Symantec Corporation