Re: C_FUNC in DOS
- Posted by Robert Craig <rds at EMAIL.MSN.COM> Jan 06, 1999
- 510 views
Ralf writes: > Why not add support for using .OBJ files ? > As a counterpart to the Win32-call_func () one that works with > .OBJ files rather than .DLL files. That would be a great feature, but I don't think there's any practical way to implement it. Dynamic linking is supported by the WIN32 O/S but not by DOS. A couple of years ago a user provided me with a demo program that would: - open a .OBJ file - read in the machine code for a C routine - call() the machine code It looked pretty good. You could modify and recompile the C function and then run the Euphoria demo program. However: - the .OBJ had to be created by a specific C compiler (GNU I think) - a special compile option had to be supplied to that compiler - parameters could not be passed - the routine could not call any other routines, not even library routines - the routine could not reference any global C variables Given these restrictions, and the difficulty in overcoming some of them, I've never proceeded with DOS "DLL" support. Maybe a "third-party" could try to improve on the demo above, for some specific C compiler. I don't think this necessarily requires any support from ex.exe Bernie Ryan writes: > If I allocate memory at the begining of a program does that > memory stay in scope throughout the whole program ? Yes, you can use it until you free() it, or your program terminates. > When one eu function calls an eu function does it use the stack? No. It uses an internal Euphoria "call-stack" in memory which has nothing to do with the machine stack. > Is there a way to locate the stack, and push something on the stack. > and recover it without disturbing eu ? You have to use PUSH and POP machine instructions in a section of machine code. > How does C_FUNC and C_proc work in win32lib ? > I understand that it uses the DLL's but this same thing will work > if define_c_function and define_c_proc were written to work on > any hex sequence of code that was poked into memory as long > as it was setup in the format of a dll. define_c_func() and define_c_proc() call an O/S routine that returns the machine address of the C routine. This address is saved in a table, and a small integer value is returned to you. Later, when you call c_func() or c_proc(), passing the small integer value, Euphoria indexes into the table, gets the address, the number and type of parameters etc., and makes the call. There's a standard C calling convention on WIN32 for making such calls, that requires the arguments to be pushed onto the machine stack (the last arg is pushed first as I recall). Regards, Rob Craig Rapid Deployment Software http://members.aol.com/FilesEu/