← Macintosh C Programming By Example 1991

Macintosh C Programming By Example 1991

From the originals

13 scans

Machine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.

These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.

PDF page 12

1: PROGRAMMING THE MACINTOSH WITH THINK C Pascal has a reputation as a fine teaching language. Better still for our purposes, it was the language of choice internally at Apple as the Macintosh was developed. The data structures that the Toolbox and the operating system expect to deal with are forms Pascal directly understands. Two problems made us avoid Pascal: Coding pointers and handles-two basic types of Macintosh data-is somewhat cumber- some in Pascal; and accessing low-level data such as individual bits is possible only through Toolbox macros. Assembly language, of course, lets you access the bits and bytes in memory, but we ruled it out because creating data and control structures tends to become quite com- plex. Assembly language has no data structures or structured loops, leaving you to invent them yourself. And good assembly language code is difficult to read quickly. That left us with C, the language we have used for most of our programming projects in the last five years. We feel strongly that C does a better job of showing the control and manipulation of data structures for Mac programming than any other language does. The only real drawback to using C is that the Macintosh's native language is Pascal, and C data types and calling conventions differ from their Pascal counter- parts. Another drawback is that C lets you do some very stupid things. C is a laissez- faire language: It usually lets you do what you want to do as far as assignments and pointer arithmetic are concerned, but, because it's so lenient about checking for compatible data types across assignment operations, it will let you do nonsensical things in your code without much warning or complaint from the compiler. C assumes that you know what you're doing. This is the Pascal aficionado's major complaint against C, but it's a feature that we enjoy. Be forewarned, though, that novice C programmers are virtually guaranteed to fall into one of C's traps at some point early in their careers. Guard against C's traps by double-checking every change you make to a program and by constantly double-checking your data types. As a prospective Mac C programmer, you need to be familiar with the syntax and se- mantics of the C programming language. Sure, we'll supply you with working code, but you 'll need to understand the language if you want to write your own code and get the most benefit from this book. You'll need to learn the fundamentals of C- variable declarations, assignments, function definitions, function calls. Don't worry if you don't have any experience with the language-we'll meet you halfway. Chap- ter 3 is a brief C primer you can use as a reference. We do suggest that you pick up a copy of Kernighan and Ritchie's The C Programming Language, published by Pren- tice Hall, if you're serious about learning C. This classic, known by the blue Con its cover, was the first book on the language. Recently revised, K&R is still our favorite, despite competition from dozens of other introductory books on C. Although the Kernighan and Ritchie book is excellent for learning how to use C, it doesn't teach you a thing about programming the Mac. As you read along in this book, we'll alert you to common pitfalls that await the new C programmer of the Mac, and we'll beef up our efforts when we get to more advanced topics like data structures, pointers, and dynamic memory allocation-and their relationship to the Mac. Of course, we think the best way to learn a language is by example. In each 5

Reading notes: Text appears to be a book excerpt rather than an advertisement; no primary heading is printed. Page number '5' appears at the end and was not treated as a date.

Printed product names
Think C · Macintosh · Toolbox · Pascal · C
Languages
English