[comp.sys.mac.programmer] Using THINK C from THINK Pascal

fry@math.harvard.edu (David Fry) (03/01/91)

I'm trying to interface a THINK C library with a friend's THINK 
Pascal program.  My C function is defined:

pascal void MyFunc(Ptr aPtr, short aShort, unsigned char aByte);

The problem is how to define it in Pascal and pass parameters to it 
so that aByte gets the proper values.  I've tried a variety of 
things, and only

PROCEDURE MyFunc(aPtr: Ptr; aShort: INTEGER; aByte: BOOLEAN);

comes close.  Defining aByte as a CHAR or Byte still uses 16-bits, so 
only the high byte is getting passed to the C routine.  BOOLEAN uses 
8-bits, but it is equivalent to a char, rather than an unsigned char, 
so the high bit is unusable.

Should I define a type of PACKED ARRAY [1..1] of CHAR, or some such?

Thanks for any help.

David Fry                               fry@math.harvard.EDU
Department of Mathematics               fry@huma1.bitnet
Harvard University                      ...!harvard!huma1!fry
Cambridge, MA  02138            

Lawson.English@p88.f15.n300.z1.fidonet.org (Lawson English) (03/03/91)

David Fry writes in a message to All

DF> pascal void MyFunc(Ptr aPtr, short aShort, unsigned char aByte); 

DF> PROCEDURE MyFunc(aPtr: Ptr; aShort: INTEGER; aByte: BOOLEAN); 

DF> Should I define a type of PACKED ARRAY [1..1] of CHAR, or some 
DF> such? 

As C has the more versatile way of defining parameters, why not redefine your
C function to interface properly with the Pascal, rather then try to force Pascal
to interface properly with the C? As you have the source to both, this shouldn't
be a problem. If it is, then you might define a glue routine in C that calls
your routine after making all necessary adjustments...


Lawson
 

--  
Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!300!15.88!Lawson.English
Internet: Lawson.English@p88.f15.n300.z1.fidonet.org