gt0657c@prism.gatech.EDU (geoff george) (10/15/90)
I've just started using MacProtos.h, a copy of which I got from the info-mac archives at sumex. (Or maybe UT rice, not certain.) I like it a lot, since I'm compulsive about using what little typing C allows. (Yeah, I know, "Strong typing is for people with weak memories." I used to quote that a lot before ANSI C, but now that I can have type checking on parameters if I want it, well isn't weak memories why we don't all program in binary right down on the bare silicon? But I digress.) I've just encountered a problem. In trying to call FillRect(), I passed it the global "white" and it complained. I looked everything up, and found that IM (I have the promo edition, the old "phone book" I-III) gives the following declarations: TYPE Pattern = PACKED ARRAY [0..7] OF 0..255; VAR white: Pattern; FillRect (r: Rect; pat: Pattern); Think C 4's <Quickdraw.h> gives: typedef unsigned char Pattern[8]; extern Pattern white; which makes "white" a "char *". MacProtos.h gives: pascal void FillRect(Rect *r, Pattern *pat); which makes pat a "char * *" or "char * []". I believe that second parameter should be "Pattern pat", not "*pat". I also found the same thing everywhere that "Pattern" occurs in MacProtos.h. Am I missing something, like is Pattern a struct in MPW C or older Think (LightSpeed) Cs, or has no-one used FillRect() and MacProtos.h both in the same program? Out of curiousity, how widely _is_ MacProtos.h used? As I said, I personally love it, since it gives me a little more type checking that Think C has built in for Mac traps. regards, geoff george -- geoff george geoff@remvax.gatech.edu (my vax) or gt0657c@prism.gatech.edu (a touch of warmth from GaTech OCS) "Ordinary f---ing people - I hate 'em. Ordinary person spends his life avoiding tense situations; repo man spends his life getting INTO tense situations."
phils@chaos.cs.brandeis.edu (Phil Shapiro) (10/16/90)
In article <15187@hydra.gatech.EDU> gt0657c@prism.gatech.EDU (geoff george) writes:
In trying to call FillRect(), I passed it the global "white" and it
complained. Think C 4's <Quickdraw.h> gives:
typedef unsigned char Pattern[8]; extern Pattern white;
which makes "white" a "char *". MacProtos.h gives:
pascal void FillRect(Rect *r, Pattern *pat);
which makes pat a "char * *" or "char * []". I believe that second
parameter should be "Pattern pat", not "*pat".
In C, an array name is synonymous with its address when used as a
parameter. Therefore, FillRect(&r, &white) and FillRect(&r, white)
are (in terms of C) equally correct, since they are semantically
equivalent. So, why did the creators of MacProto decide to use
"Pattern *"? The User's Manual for C says that arguments to toolbox
functions that are larger than 4 bytes must be passed by address.
Since sizeof(Pattern) == 16, they chose to use the Pattern's address.
Out of curiousity, how widely _is_ MacProtos.h used? As I said, I
personally love it, since it gives me a little more type checking
that Think C has built in for Mac traps.
I don't know how widely it's used -- but I use it all the time.
-phil
--
Phil Shapiro Technical Support Analyst
Language Products Group Symantec Corporation
Internet: phils@chaos.cs.brandeis.edu