[comp.sys.mac.programmer] TrapAvailable

tarr-michael@CS.YALE.EDU (michael tarr) (02/23/91)

When I try to use the call TrapAvailable as per the latest issue of
MacUser to find out if Gestalt is around, Think C 4.0.2 complains that
"TrapAvailable" is undefined.

What am I missing?

Mike Tarr
tarr@cs.yale.edu
-- 
 **************************************************************************
 * Michael J. Tarr                              Department of Psychology  *
 * tarr@cs.yale.edu                             Yale University           *
 **************************************************************************

mneerach@iiic.ethz.ch (Matthias Ulrich Neeracher) (02/23/91)

In article <29004@cs.yale.edu>, tarr-michael@CS.YALE.EDU (michael tarr) writes:
>
>When I try to use the call TrapAvailable as per the latest issue of
>MacUser to find out if Gestalt is around, Think C 4.0.2 complains that
>"TrapAvailable" is undefined.
>
>What am I missing?

Simple: There is no such trap as TrapAvailable (yet). A simple method is
to compare the address of the trap, obtained with NGetTrapAddress, with
the trap address of the _Unimplemented trap ($A89F, I believe, but better
look it up). If they are the same, the trap is not available.

While this method works on all reasonably new macs, a more complicated
incantation is needed if you are worried about compatibility with 
64K ROM macs.

Matthias

-- 
Matthias Neeracher                                   mneerach@iiic.ethz.ch
   "These days, though, you have to be pretty technical before you can 
    even aspire to crudeness." -- William Gibson, _Johnny Mnemonic_

Steve.Ihde@f421.n109.z1.fidonet.org (Steve Ihde) (02/24/91)

In article <29004@cs.yale.edu> tarr-michael@CS.YALE.EDU (michael tarr)
writes:
mt> When I try to use the call TrapAvailable as per the latest issue of
mt> MacUser to find out if Gestalt is around, Think C 4.0.2 complains that
mt> "TrapAvailable" is undefined.
mt> What am I missing?
 
Well, TrapAvailable() doesn't exist.  Here, however, is the souce code
for it:
 
    Boolean TrapAvailable(short tNumber,TrapType tType)
    {
    
    /* define trap number for old MPW or non-MPW C */
    #ifndef _Unimplemented
    #define _Unimplemented 0xA89F
    #endif
    
    /* Check and see if the trap exists. */
    /* On 64K ROM machines, tType will be ignored. */
    
       return( NGetTrapAddress(tNumber, tType) !=
               GetTrapAddress(_Unimplemented) );
    
    }
 
I think that I got the code either from a Tech note or from the Q&A
stack.  TrapType is an enumerated type of OSTrap and ToolTrap, I
believe.


--  

        Steve Ihde, Steve.Ihde@f421.n109.z1.fidonet.org
      via The Black Cat's Shack's FidoNet<->Usenet Gateway
          blkcat.fidonet.org   and   Fidonet 1:109/401