Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!unmvax!pprg.unm.edu!hc!lll-winken!uunet!pdn!rnms1!alan From: alan@rnms1.paradyne.com (0000-Alan Lovejoy(0000)) Newsgroups: comp.lang.modula2 Subject: Re: Help!! Message-ID: <5932@pdn.paradyne.com> Date: 13 Apr 89 21:42:01 GMT References: <13400002@bucc2> Sender: news@pdn.paradyne.com Reply-To: alan@rnms1.paradyne.com (0000-Alan Lovejoy) Organization: AT&T Paradyne, Largo, Florida Lines: 63 In article <13400002@bucc2> larr@bucc2.UUCP writes: > >HELP!!!!! >Hi, This is my first official post. >I am a novice Modula-2 programmer, basically using JPI M2 for class >work. I am currently doing an independent study in OOP and would like >to begin work on an extension to M2. The biggest problem I am having >is trying to figure out how to do pointers to procedures, as in C. > Any help would be greatly apprieciated. > Larry Schoeneman, Bradley University Use a procedure variable: MODULE Example; FROM SYSTEM IMPORT ADR; FROM InOut IMPORT WriteString, WriteLn; VAR p: PROCEDURE; (* This is a procedure variable. It is physically the same thing as C function pointer. This one ("p") is type-compatible with any procedure having no arguments. *) q: POINTER TO PROCEDURE; (* This is a pointer to a procedure variable. It is physically the same thing as a pointer to pointer to function in C. *) write: PROCEDURE(ARRAY OF CHAR); (* This procedure variable is compatible with any procedure expecting an open array of characters as the single value parameter. *) PROCEDURE P; BEGIN write("This is P"); WriteLn; END P; PROCEDURE Q; BEGIN write("This is Q"); WriteLn; END Q; BEGIN write := WriteString; p := P; p; (* invokes P *) q := ADR(p); p := Q; q^; (* invokes Q *) END Example. Alan Lovejoy; alan@pdn; 813-530-2211; AT&T Paradyne: 8550 Ulmerton, Largo, FL. Disclaimer: I do not speak for AT&T Paradyne. They do not speak for me. __American Investment Deficiency Syndrome => No resistance to foreign invasion. Motto: If nanomachines will be able to reconstruct you, YOU AREN'T DEAD YET.