Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!pasteur!agate!garnet.berkeley.edu!elcond From: elcond@garnet.berkeley.edu (Gregory Dow) Newsgroups: comp.sys.mac.programmer Subject: Bug in LSC Message-ID: <7216@agate.BERKELEY.EDU> Date: 27 Feb 88 00:03:55 GMT Sender: usenet@agate.BERKELEY.EDU Reply-To: elcond@garnet.berkeley.edu.UUCP (Gregory Dow) Organization: University of California, Berkeley Lines: 45 Keywords: C, Bug I have tripped over what appears to be a bug in LightSpeed C's CallPascal routines. When calling a Pascal function (a function declared as pascal so that it may be used as a toolbox hook) indirectly through a pointer, the LSC manual (page 9-7) states that you must use the one of the CallPascal library functions. The argument list to CallPascal should be the arguments to your function, with a pointer to your function as a last, extra argument. This is necessary because the calling conventions in C and Pascal are different: they put the arguments on the stack in different orders. However, when I tried calling CallPascal with my function pointer as the last argument, the system crashed because it tried to treat my FIRST argument as a function pointer. Reversing the order of the arguments to CallPascal worked. It appears that CallPascal is confused about in which to pass the arguments. Example: pascal void MyFunc(arg1, arg2) { ... some code } Calling MyFunc from another function: typedef void (*VoidFunc()); VoidFunc funcPtr; CallPascal(arg1, arg2, funcPtr); /* does not work. Thinks arg1 is a function pointer */ CallPascal(funcPtr, arg2, arg1); /* This works. Order of arguments is reversed */ (*funcPtr)(arg2, arg1); /* This also works because C passes argmument from left-to-right */ /* and Pascal from right-to-left. */ Gregory Dow ARPA: elcond@garnet.berkeley.edu Chemical Engineering Dept. UUCP: {uwvax, decvax, ihnp4, ...}!ucbvax University of California !elcond%garnet.berkeley.edu Berkeley, CA 94720 BITNET: POLYDOW@UCBCMSA