www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/22/11:01:13

Date: Tue, 22 Jul 1997 08:00:26 -0700 (PDT)
Message-Id: <199707221500.IAA26331@adit.ap.net>
Mime-Version: 1.0
To: NoHero69 AT aol DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Calling functions indirectly (was: ...)
Cc: djgpp AT delorie DOT com

You wrote:
>One quick question.  If I have a pointer that points a function, what is the
>syntax of calling the procedure via the pointer?  Is it a simple CALL
><whatever> in ASM,
Yes. Be sure to push its args first, and adjust the stack afterwards.
> and is there a way to do it outside the bounds of ASM?
Yes.

int do_something(void)
{
   printf("Hello there\n");
   return 0;
}

int call_this_function(int (*f)(void))
{
   int r;
   r = f();
   printf("Function returned %d\n",r);
   return 0;
}

void top_level(void)
{
   call_this_function(do_something);
}

HTH

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019