Think C Tutor
Volume Number: 5
Issue Number: 10
Column Tag: MacOOPs!
A First Look At THINK C 4.0 
By Alastair Dallas, Glendale, CA
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
Think C 4.0 First Look
[Alastair Dallas is the president of Software Magic, a developer of (as yet
unreleased) Macintosh software. He moonlights as a Sr. Software Designer for the IBM
PC side of Ashton-Tate, publisher of FullWrite Professional, Full Impact and dBASE
Mac, none of which Mr. Dallas had anything to do with.]
If you are like me, you were surprised by Symantec’s announcement at the end of
July that a brand new, object-oriented version of their popular C compiler would be
available soon. Rumors that principal author Michael Kahl was working on
object-oriented extensions to his LightspeedC package predate the June, 1988 release
of version 3.0. When Apple warned us this spring that “you’d better learn
object-oriented programming” if you want to program your Mac in the future,
perhaps you, like me, were hoping for an object-oriented programming system (oops)
that was as accessible as THINK’s LightspeedC to learn with.
THINK C (they dropped the name Lightspeed with this release) is nearly the C
version of MacApp we’ve been waiting for. The new version supports Object
Pascal-style extensions and a generic application which you can customize. And it’s
available now. Symantec must have waited until THINK C 4.0 was ready to ship before
announcing it, because my upgrade order was filled in less than a week-much faster
than the upgrade to 3.0. The upgrade price is $69 to registered owners, and the retail
price of 4.0 is said to be over 50% higher than 3.0.
What do you get for your money? A lot. In addition to the popular integrated
compiler, linker, editor, source-level debugger and make facility, this release
includes version 1.0 of the THINK Class Library (TCL) which encapsulates most of the
standard Macintosh user interface. The C compiler includes improvements making it
95% conformant with the draft ANSI C standard as well as object-oriented extensions
which make the THINK Class Library possible.
THINK C 4.0 arrives on four disks, including full source code to a 100%
ANSI-conformant library, Macintosh ROM Toolbox “glue” libraries, several example
programs (non-oops examples from 3.0 and Art Class, a fairly full-featured
MacPaint-type application written using TCL), and template projects (Starter and
Pedestal) which you can use to build your own applications.
Two soft-cover books describe the product. The 512-page User’s manual is
essentially the 3.0 user’s manual with 250 pages of object-oriented material added as
section four. The 37 Core Classes of the TCL are described here, one to a chapter.
While the size of the other book, the Standard Libraries Reference, is about the same
as it was in 3.0, the content has changed profoundly because the functions and header
files are now organized according to the ANSI standard.
If you are familiar with version 3.0, you’ll want to hear exactly what’s new
about 4.0:
• Object extensions to C (described below)
• THINK Class Library (almost MacApp for C)
• ANSI C compatibility
• Prototypes for function definitions
• # (stringize) and ## (concatenate) preprocessor operators
• long double type, long double literals
• ANSI standard library w/ glass tty example
• Inline assembler extensions for 68020 and 68881 instructions
• “Once-only” headers
• Multi-segment code resources
• Better cdev (control panel device) support
• Inline assembler functions (makes glue functions more efficient)
Introduction to Object-Oriented Programming
The lecturer at a recent seminar explained that if he wanted to sell his cat just
now (to a bunch of programmers), he would advertise it as an object-oriented cat.
Object-oriented, the buzzword, has been around since the late 1970s, when BYTE
magazine broke the story about Smalltalk ( which, legend has it, got Steve Jobs
interested in Xerox PARC in the first place).
The term object-oriented may be used to describe almost anything, including a
cat, but it almost always promises reusable code. THINK C (TC) is no exception; the
system makes it easy to take a generic piece of code and customize it by overriding one
or more of its functions. Once you customize the generic window code so that sizing the
window maintains its aspect ratio (width / height), you then have a new type of
generic window object that you can specialize in other ways for your next project.
Objects are a way of grouping data together with the functions which manipulate
that data. All the books tell you that objects mimic the real world, but I think a better
example is that objects mimic Macintosh user interface elements. Take windows, for
example. A window object has data (the WindowRecord, which includes a grafPort, and
perhaps some other variables) and it has certain operations it knows about. These
operations are called methods in the literature, but they’re implemented as functions
in THINK C. For example, a window can change size, move (drag), hide, show and so
on. An application might have several windows, each capable of the same operations,
but each window would have a different WindowRecord.
In THINK C, you essentially address the WindowRecord (actually the Window
object) and say “hide yourself.” THINK C knows how to find the functions which all
Window objects have in common. If you want to customize the Window object as I
described above, for example, you create a new object type (called a class) that is
derived from the Window class with, in this case, a special “change size” function. If
you tell your special Window to do something ordinary like hide itself, THINK C will
use the same function that any Window would use for that command-your special
Window object only provides the code that makes it different from a normal Window.
For more reading about object-oriented concepts as they apply to the Macintosh,
I recommend “Object-Oriented Programming for the Macintosh” by Kurt Schmucker
(Hasbrouck Heights, NJ:Hayden, 1986, ISBN 0-8104-6565-5). This book
emphasizes MacApp, but describes the Macintosh user interface in object-oriented
terms and provides an overview of several oops languages as well, such as Lisa Clascal,