From: jbro on 28 Nov 2009 04:21 On Nov 27, 8:53 am, Paul Tarvydas <tarvy...(a)visualframeworksinc.com> wrote: > > The C code in question is > > > int _stdcall myarray(int sz) > > { > > int *end; > > int pin [4]={sz,2,73,4}; > > end= pin; > > return *end; > > } > > > I don't know what _stdcall does but I doubt that it is so powerful that > > it fixes the issue of returning a pointer to automatic storage. > > Yes, I missed the "sz" stuck in the array initializer. This C code is > utterly wrong. > You are right about stdcall, but that is not the issue and neither is the "sz". What Spiros is trying to say is that once your function returns (to Lisp) pin's memory is deallocated and so now end points somewhere it shouldn't (i.e. to already deallocated memory). You need to create your array on the heap with malloc and then arrange for Lisp to call into a function that calls free to deallocate the memory. Write a main function in C and test your function -- you'll get the same seg fault. It has nothing to do with Lisp. |