Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!ut-sally!brian From: brian@ut-sally.UUCP Newsgroups: comp.sys.mac Subject: Re: rect.top vs: rect.topLeft in C Message-ID: <9826@ut-sally.UUCP> Date: Mon, 7-Dec-87 13:52:23 EST Article-I.D.: ut-sally.9826 Posted: Mon Dec 7 13:52:23 1987 Date-Received: Sat, 12-Dec-87 11:44:12 EST References: <870053@hpcilzb.HP.COM> <3424@husc6.harvard.edu> <2571@watcgl.waterloo.edu> Organization: U. Texas CS Dept., Austin, Texas Lines: 49 Summary: why nobody does this In article <2571@watcgl.waterloo.edu>, kdmoen@watcgl.waterloo.edu (Doug Moen) writes: } Although I haven't seen this exact trick used in any Mac C environment } so far, it *is* possible to define Rect so that you can use the } syntax described in Inside Macintosh for accessing its fields: } } typedef struct { } Point topLeft; } Point botRight; } } Rect; } } #define top topLeft.v } #define left topLeft.h } #define bottom botRight.v } #define right botRight.h } } Note that LightSpeed C defines top,left,bottom and right as fields } and topLeft,botRight as macros, while the above implementation does } the reverse, *and* gives you a cleaner syntax. } -- } Doug Moen } University of Waterloo Computer Graphics Lab } UUCP: {ihnp4,watmath}!watcgl!kdmoen } INTERNET: kdmoen@cgl.waterloo.edu The problem here is that you can no longer use variables with the names top, left, bottom or right. One of the old Megamax C's did something like this as I recall. (It wasn't necessarily this example.) I wrote a program in which I used a variable called "top" (using this as an example.) We all know how good most C compilers are at explaining the problem... I spent quite some time trying to figure out why int top; gave a "Syntax Error." Variables with the names top, left, bottom and right are much more common in C programs than variables named topLeft, botRight, so that's why the macros are done in a non-intuitive manner. Brian H. Powell UUCP: ...!uunet!ut-sally!brian ARPA: brian@sally.UTEXAS.EDU _Work_ _Not Work_ Department of Computer Sciences P.O. Box 5899 Taylor Hall 2.124 Austin, TX 78763-5899 The University of Texas at Austin (512) 346-0835 Austin, TX 78712-1188 (512) 471-9536