TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Neil Heller
from: Darin McBride
date: 2004-04-29 15:52:48
subject: Function Pointer Redux

Hello Neil!

Replying to a message of Neil Heller to John Guillory:

 NH> 
 JG>>> -> typedef void * (*x) (void *)

 JG>>> -> What does this statement declare?

 JG>>> -> What is x?
 JG>>   I'm not an expert on C, but it appears like

 JG>> X is a pointer to a function that returns (I think a generic pointer)
 JG>> and takes on a generic pointer (void *).... In other words

Hmmm...

 NH> It seems to me that x is the return type from the function.  What's 
 NH> being returned is a pointer to that type.

 NH> I was wondering if the original statement is recursive?

Not at all.

typedef void* (*callback_t)(void *);
error_t do_stuff(callback_t function, void* data)
{
  error_t error = NO_ERROR;
  /* stuff, stuff, stuff */
  data = function(data);
  /* stuff, stuff, stuff */
  return error;
}

Now you can write any number of callback functions that match the
callback_t typedef's prototype, and use them in the do_stuff function.  The
function that you pass in must be a function that takes a pointer, and
returns a pointer.

Darin

---
* Origin: Tanktalus' Tower BBS (1:250/102)
SEEN-BY: 633/267 270
@PATH: 250/102 99 10/345 106/1 2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.