cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/02/28/18:10:40

Sender: nate AT cartsys DOT com
Message-ID: <36D9BD2F.A05C8E55@cartsys.com>
Date: Sun, 28 Feb 1999 14:03:27 -0800
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.1 i586)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: Pointers to functions.
References: <7b9jku$o7o$1 AT news6 DOT svr DOT pol DOT co DOT uk>
Reply-To: djgpp AT delorie DOT com

> <------------------------ wrote:
> 
> Hi,
> 
> I'm in the process of writing a (very primitive) scrolling shoot-em-up
> like space invaders,
> and in designing the core of the sprite moving program, I have chosen
> to have every object
> call it's update function each frame. All the objects share a common
> data type, so I wanted
> to use function pointers. The problem is, I've never uesd them before.
> Just wanted to know
> how to prototype them (if any changes are needed) and how to specify
> them in my object_t
> structure. I'd also appreciate any help in how I'm supposed to assign
> functions to the pointers,
> and how to call those functions.

Please don't post in HTML.

A function pointer is declared basically like this:

int (*this_is_a_function_pointer)(int, int);

which makes `this_is_a_function_pointer' a pointer to a function taking
two `int' arguments and returning `int'.  Assuming you have a function
like:

int foo(int, int);

you can then do

this_is_a_function_pointer = foo;

or

this_is_a_function_pointer = &foo;

In the case of functions, you can use the `&' operator or not; whichever
you feel is clearer.

There is a program on Simtelnet called `cdecl' that can help with
complicated declarations.
-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


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