[comp.sys.mac.programmer] Problem linking Think C 4.0 and LSP.

bogstad@sdbio2.ucsd.edu (Bill Bogstad/Sejnofski) (02/11/90)

I'm trying to link Pascal and C code in Symantec's Think environment, and I ran
into a few problems. I was wondering if anybody could help me out.  I wrote the
C code declaring routines pascal void as necessary and chose the build library
option. Evrything seemed to work fine. I wrote a c shell that emulated what the
Program I am trying to link to was doing.  I then proceeded to debug my library
until it worked perfectly.  Now I tried to link it into pascal, but the library
no longer worked.  After numerous attempts at trying to debug it here, I finally
decided that the only way to see the values my library was producing was to
write them to a file.  I set up the following test program and made it a library

pascal void test()
{

int refNum;
Str255 name;
Str255 sTemp;
OSErr err;
double temp;
int vRefNum;

name[0]=1;
name[1]=a;      /* You can't initialize this as a \p string and create won't
                   accept a direct argument */
err=GetVol(sTemp,&vRefNum);
err=Create(name,vRefNum,'TEST','DBUG');
err=FSOpen(name,vRefNum,&refNum);

temp=1.0;
count=sizeof(double);
err=FSWrite(refNum,&count,&temp);

FSClose(refNum);
}


What resulted in the file called "a" was a 12 byte numerical representation of
4.48652018267028476e-3934 ! I tried making temp a static instead of an automatic
variable..nothing worked.  Everything I could think of to initailize temp as a
floating point 1.0 failed. ( The same thing however, when called by my C shell,
produced 1 in the file!)

The pascal project included SANELib881.lib and I compiled the C Library with the
68881 code generation option checked.  Am I missing something? Why does this not
work in Pascal? Isn't everything precompiled so the current running environment
should have no effect? Which causes me to ask the question as to why macros are
useless in this respect.  A macro defining PI as 3.14... did not even work. I
passed it to a variable and the variable came out -1.1...e1170.  A Boolean
comparison based on the following code failed to produce anything:

temp=PI;
if (temp==PI)
   SysBeep(60);

I have absolutely no idea what's wrong. I called Symantec technical support but
they have not responded yet.  Does anyone have any guess as to why this isn't
working?  Also, is there some better test that I could preform to track down
the error?  Any and all suggestions would be greatly appreciated.

                       Thanx in advance for your help,

              
                                        Chris.

Chris Ziomkowski                        The SALK Institute, CNL
(619) 453-4100 x579                     10010 N. TorreyPines Rd.
chris@cajal.sdsc.edu                    La Jolla, CA 92137