yahnke@vms.macc.wisc.edu (Ross Yahnke, MACC) (08/17/90)
There is this nifty little routine in the MacTech Journal that
decribes how to write a Think C macro to call an assembly routine
that will pop the state of a handle onto the stack and then lock
the handle. Also described is the corresponding routine to pop
the state back off the stack. I can't get it to compile.
The macro is:
#define _PushLock(H) asm \
{ move.l H,a0 \
_HGetState \
move.b d0,-(sp) \
move.l H,a0 \
_HLock \
} /* PushLock */
My C call is:
_PushLock((*Major)->Contrived.Complex.aHandle);
Think C chokes when compiling/assembling the above line with
the message "Pointer is required". This is presumably occuring
when it tries to assemble:
move.l (*Major)->Contrived.Complex.aHandle,a0
HOWEVER, if I do the following, Think C has no problems:
...
Handle wubba;
...
wubba = (*Major)->Contrived.Complex.aHandle;
_PushLock(wubba);
Any clues what's going on? (The ".aHandle" field is declared to be
a handle...)
>>> yahnke@macc.wisc.edu <<<beard@ux5.lbl.gov (Patrick C Beard) (08/17/90)
In article <4225@dogie.macc.wisc.edu> yahnke@vms.macc.wisc.edu (Ross Yahnke, MACC) writes: #There is this nifty little routine in the MacTech Journal that #decribes how to write a Think C macro to call an assembly routine #that will pop the state of a handle onto the stack and then lock #the handle. Also described is the corresponding routine to pop #the state back off the stack. I can't get it to compile. # #The macro is: # #define _PushLock(H) asm \ # { move.l H,a0 \ # _HGetState \ # move.b d0,-(sp) \ # move.l H,a0 \ # _HLock \ # } /* PushLock */ # #My C call is: # _PushLock((*Major)->Contrived.Complex.aHandle); # #Think C chokes when compiling/assembling the above line with #the message "Pointer is required". This is presumably occuring #when it tries to assemble: # move.l (*Major)->Contrived.Complex.aHandle,a0 Think about what this means. What addressing mode could possibly be used to generate the correct code with all of these dereferences? You are mixing C and assembly a little TOO freely. The only way this macro can work is if you use a temporary which is on the stack, or in a register. Now, this version will work whatever you pass it: #define _PushLock(H) \ { Handle temp = H; \ asm { \ move.l temp,a0 \ _HGetState \ move.b d0,-(sp) \ move.l temp,a0 \ _HLock \ }} /* PushLock */ It works because you force all the complicated addressing to happen automatic- ally and the compiler does all the work. temp is always relative to A6. I hope this helps. -- ------------------------------------------------------------------------------- - Patrick Beard, Macintosh Programmer (beard@lbl.gov) - - Berkeley Systems, Inc. ".......<dead air>.......Good day!" - Paul Harvey - -------------------------------------------------------------------------------