Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!bloom-beacon!bu-cs!dartvax!eleazar.dartmouth.edu!earleh From: earleh@eleazar.dartmouth.edu (Earle R. Horton) Newsgroups: comp.sys.mac.programmer Subject: Re: MPW C <-> Lightspeed C header files Message-ID: <14321@dartvax.Dartmouth.EDU> Date: 10 Jul 89 23:15:23 GMT References: <14107@swan.ulowell.edu> Sender: news@dartvax.Dartmouth.EDU Reply-To: earleh@eleazar.dartmouth.edu (Earle R. Horton) Organization: Thayer School of Engineering Lines: 51 In article <14107@swan.ulowell.edu> jkeegan@hawk.ulowell.edu (Jeff Keegan) writes: > >I'm using Lightspeed C (3.01) on a MacIIx. I'm trying to convert a MPW C >header file so I can use it in Lightspeed C. I want to know how to declare >a pascal PROCEDURE (a function that doesn't return a value) in Lightspeed C. > >In the MPW header file, it says something like > > typedef pascal void (*MyProc) ( > int argument1; > char argument2; /* etc.. these are made up */ > Ptr argument3); > > Trying to precompile this from Lightspeed C gives me "invalid storage class". In the declaration above, MyProc is a POINTER to a pascal PROCEDURE, and not the PROCEDURE itself. I assume you want to declare a variable to hold the address of a procedure declared elsewhere, which variable is declared to follow the Pascal calling conventions. How you do this depends on whether you intend to call the function pointed to directly, or whether you intend to pass the pointer to the Toolbox to be called from the Toolbox, as in Dialog Filter Proc. If you need to call a Pascal PROCEDURE, and you have its address but not its name, then you have to use some sort of glue to call it. This was true in MPW 2.0.2, and appears to have been fixed in MPW 3.0, thus the strange new syntax that will cause other C compilers to gag. From looking at TLSC code I have seen here and there, there exist library routines named something like CallPascal() to do this for you. If you want to write a Pascal callback routine, called by some part of the Toolbox, then that should be easy. ProcPtr MyProc; pascal void MyActualProc(args) types args; { /* Some code. */ } MyProc = (ProcPtr)MyActualProc; MyProc now holds the same thing as intended in the MPW 3.0 header files, namely a pointer to a Pascal PROCEDURE. You can pass it to Toolbox routines, but you can't call it directly unless you use some glue. Earle R. Horton "People forget how fast you did a job, but they remember how well you did it." Salada Tag Lines