[comp.sys.mac.programmer] MPW C <-> Lightspeed C header files

jkeegan@hawk.ulowell.edu (Jeff Keegan) (07/09/89)

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".

What *I* interpretted the error to mean was that there wasn't a pascal type
"void" in Lightspeed Pascal (a guess, assuming that either there WAS a void
type in MPW Pascal, or it was a special case of the C compiler to look for
void in a pascal declaration).

Also, I've noticed that in Lightspeed C you don't give paramater lists at
that point. I've tried using

        typedef pascal void (*MyProc) ()

also, and it still doesn't work.. 

Another example was this :  The MPW code said

        typedef void (*MyOtherProc) (struct MyStruct *thestruct)

This said "paramater list is inappropriate here" in Lightspeed C so I
replaced it with

	typedef void (*MyOtherProc) ()

which seems to work.

Questions :
	1) Am I correct in my change for that second example (the typedef
	   for MyOtherProc)?

	2) How do I interpret or translate the first one?

Thanks for your help in advance..

..Jeff Keegan

-------------------------------------------------------------------------------
| Jeff Keegan                | I clutch the wire fence until my fingers bleed |
| jkeegan@hawk.ulowell.edu   | A wound that will not heal                     |
|----------------------------| A heart that cannot feel                       |
| This space intentionally   | Hoping that the horror will receed             |
| left blank                 | Hoping that tomorrow we'll all be freed  -RUSH |
-------------------------------------------------------------------------------

siegel@endor.harvard.edu (Rich Siegel) (07/09/89)

In article <14107@swan.ulowell.edu> jkeegan@hawk.ulowell.edu (Jeff Keegan) writes:
>
>In the MPW header file, it says something like
>
>	typedef pascal void (*MyProc) (
>            int argument1;
>            char argument2;  /* etc.. these are made up */
>            Ptr argument3);

	In TLSC, procedure's can't be typedef'd as "pascal".

>        typedef void (*MyOtherProc) (struct MyStruct *thestruct)

	I'm not a C guru, but I suspect that a prototype at this point
is an ANSI C feature, which isn't yet supported by TLSC.

		--Rich



~~~~~~~~~~~~~~~
 Rich Siegel
 Staff Software Developer
 Symantec Corporation, Language Products Group
 Internet: siegel@endor.harvard.edu
 UUCP: ..harvard!endor!siegel

 I classify myself as a real developer because my desk is hip-deep in
 assembly-language listings and I spend more than 50% of my time in TMON.

~~~~~~~~~~~~~~~

earleh@eleazar.dartmouth.edu (Earle R. Horton) (07/11/89)

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

lippin@skippy.berkeley.edu (The Apathist) (07/11/89)

Recently jkeegan@hawk.ulowell.edu (Jeff Keegan) wrote:
>
>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".

The problem is that "pascal" in LSC is a storage class specifier, like
"extern", "static", or "register."  IMHO, this is a pretty bizarre
idea.  This means that you can't use it in a typedef, and that you
can't use it together with other sc-specifiers.  Both of these are
annoying, but minor problems.

To get around the first problem, just leave out the "pascal."  Or, in
your case, you can use the Mac type "ProcPtr."  In your example, you
also need to remove the parameter declarations, as they aren't
supported in LSC.  To call the pointer, use the CallPascal library
routine; calling it directly would perform a C-like call.

To get around the other problem, just leave out the other
sc-specifier.  The only one that's really useful is "static," and one
can live without it fairly easily.

					--Tom Lippincott
					  lippin@math.berkeley.edu

"I enjoy working with humans, and have stimulating relationships with them"
					--HAL