abcscnuk@csuna.UUCP (Naoto Kimura) (06/27/88)
I know this question has been asked before, but does anybody have the code that could be used for Turbo Pascal 3.01 to pass a pointer to a function ? I know this could be done in 4.0 (someone posted this a little while back), but I'm having trouble writing the equivalent in 3.0. ----- type pointer = ^byte; const NearPtr : integer = 0; FarPtr : pointer = ptr(0,0); (* I know this isn't entirely * correct using the ptr * function, but this is * effectively what I had (I was * using free type union). *) function nearindirect( x : real) : real; begin inline( (* I'm not sure what I should have here *) (* forgot the hex for the indirect near jump *) {JMP NearPtr} ) end; function farindirect( x : real) : real; begin inline( (* I'm not sure what I should have here *) (* forgot the hex for the indirect far jump *) {JMP NearPtr} ) end; function foo( x : real ) : real; begin foo := x + x end; function bar( x : real ) : real; begin bar := x * x end; procedure caller ( fnptr : pointer ); var i : integer; begin FarPtr := fnptr; for i := 1 to 10 do writeln(farindirect(i)); end; begin caller( ptr(cseg,ofs(foo)) ); caller( ptr(cseg,ofs(bar)) ); end. ----- One of the reasons for wanting something that works in 3.0 is because I have a pascal to C conversion program, but it doesn't take 4.0 constructs too well. I'm presently working on a program that would eventually be translated into C. The reason for keeping around the Pascal is so that we can provide the source for a program both in C and in Pascal (some of the original stuff was written in BASIC). For those who are interested, I am using a translator program from TGL Inc. It has some strange quirks, but seems to work for the most part, except for a few annoying bugs, such as producing some output files that contain LF only as the newline sequence, not CR/LF, not handling null statements very well, and most of all not changing changing occurrances of "port[foo] := bar;" to "outp(foo,bar);" and "foo := port[bar];" to "foo := inp(bar);" (I had many occurances of these in my program. I called them some time ago and they said they were trying to work those bugs out). But one thing I could say is this was better than having no translator program at all. If you want to know the address for TGL: TGL Inc 27096 Forest Spings Ln. Corvallis, OR. 97330 BTW, does anybody have the source code to the pascal to C translator that was posted on comp.sources a while back (I already have the MS-DOS binary, but I really want the source) ? I missed them since they've set things up here so that we can't read any comp.sources articles (with the exception of things like comp.sources.d -- I suppose so we can see what we missed). Thanks in advance, //-n-\\ Naoto Kimura _____---=======---_____ (csun!csuna!abcscnuk) ====____\ /.. ..\ /____==== // ---\__O__/--- \\ Enterprise... Surrender or we'll \_\ /_/ send back your *&^$% tribbles !!
abcscnuk@csuna.UUCP (Naoto Kimura) (06/27/88)
In article <1262@csuna.UUCP> abcscnuk@csun.UUCP (Naoto Kimura) writes:
]function farindirect( x : real) : real;
] begin
] inline( (* I'm not sure what I should have here *)
] (* forgot the hex for the indirect far jump *)
] {JMP NearPtr}
^^^^^^^
oops, that should've been FarPtr
] )
] end;
//-n-\\ Naoto Kimura
_____---=======---_____ (csun!csuna!abcscnuk)
====____\ /.. ..\ /____====
// ---\__O__/--- \\ Enterprise... Surrender or we'll
\_\ /_/ send back your *&^$% tribbles !!