Gene
7/13/2011 1:30:00 AM
On Jul 12, 8:30 pm, "Bill Cunningham" <nos...@nspam.invalid> wrote:
> Keith Thompson wrote:
> > I frankly do not expect you to be able to make any use of this
> > information.
>
> I already know what some of this API does but these functions like
> this...How would you call them? I don't think the sockets API has any
> functions like that and except for rarer instances I for the most part know
> what it's doing designing a socket.
>
> "It declares bfd_error_handler_type as a typedef for a
> pointer-to-function type."
>
> So it sounds kind of like a generic function maybe if that's the right
> word? Maybe like void * ? CAn you give me an example Keith on how to call
> it?
>
> Bill
Hi Bill,
You'd write a function such as this:
#include <stdio.h>
#include <stdarg.h>
void error_handler(const char *message, ...)
{
va_list ap; // follow the variadic function protocol of stdarg.h
va_start(ap, message);
vfprintf(stderr, message, ap); // print to standard error
va_end(ap);
}
Now in later code you can kake a pointer to this function:
.....
{
bfd_error_handler_type handler;
char *instruction = "Danger, Danger!";
// For example assign the address of the function to handler:
handler = &error_handler;
// Could make decisions to assign different values to handler here.
// Make a call on the handler pointer like this:
(*handler)("Will Robinson: %s\n", instruction);
// But more likely you'll pass the handler to an API function that
// will use it to deal with internal errors. This is known as a
"callback."
api_call(&error_handler);
}