Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucsd!hub!castor!stoms From: stoms@castor.ncgia.ucsb.edu (David Stoms) Newsgroups: comp.sys.mac.programmer Subject: Re: Think C programming Message-ID: <4259@hub.UUCP> Date: 10 Mar 90 23:41:29 GMT References: <2967@dciem.dciem.dnd.ca> <1007@dms.UUCP> Sender: news@hub.UUCP Reply-To: stoms@castor.ncgia.ucsb.edu (David Stoms) Organization: U. C. Santa Barbara, Geography Department Lines: 50 In article <1007@dms.UUCP> rotberg@dms.UUCP (Ed Rotberg) writes: >From article <2967@dciem.dciem.dnd.ca>, by juana@dciem.dciem.dnd.ca (Juana Chang): >> I am trying to produce a DIALOG BOX with editable items. And I want to: >> >> GetDItem( theDialog, ITEM, &i_itemType, &hdl_item, &rect_item ); >> /* in order to get the item handle */ >> >> GetIText( &hdl_item, str_item ); >> /* in order to get the text */ >> >> This is where I get stuck... I bet every C programmer does this every now and then. Here's the file that I give to anyone that is having problems with C pointers: To pass parameters to ROM functions in C you have to be aware of a few things about Pascal. If the variable is less than or equal to four bytes long then pass it by value. Example: MoveTo(x, y); If the variable is longer than four bytes pass it by reference. Example: CopyBits(&srcBitmap, &destBitmap, &srcBounds, &destBounds, srcCopy, nil); If the variable is declared VAR then pass it by reference no matter what size it is. Example: GetPort(&AGrafPtr); (a pointer to a GrafPtr, this is the trickest trap in the ROMs!) The nice thing about these rules are that there are no exceptions. Too bad English spelling doesn't work like that. Another weird thing about C is how you reference a value buried deap down in handles and pointers. In Pascal you can build from left to right, in C you start in the middle and work your way out. Examine this example: DialogPtr dialog; dialog (WindowPeek)dialog ((WindowPeek)dialog)->ControlList (**((WindowPeek)dialog)->ControlList).contrlOwner ((**((WindowPeek)dialog)->ControlList).contrlOwner)->contRgn (**((**((WindowPeek)dialog)->ControlList).contrlOwner)->contRgn).rgnBBox