>then I would like 'bob' to produce a message like "Function f1 is not converging!" before exiting.
I'm not sure whether something akin to this may be adaptable to your problem.
Code:
#include <stdio.h>
struct sFunction
{
void (*call)(void);
const char *name;
};
void foo(void) { puts("in foo"); }
void bar(void) { puts("in bar"); }
void baz(void) { puts("in baz"); }
void qux(struct sFunction *f)
{
printf("calling %s: ", f->name);
f->call();
}
#define BIND(x) {x,#x}
int main()
{
struct sFunction table[] =
{
BIND(foo),
BIND(bar),
BIND(baz),
};
size_t i;
for ( i = 0; i < sizeof table / sizeof *table; ++i )
{
qux(&table[i]);
}
return 0;
}
/* my output
calling foo: in foo
calling bar: in bar
calling baz: in baz
*/
[edit]Maybe this is a little closer approximation.
Code:
#include <stdio.h>
#include <stdlib.h>
struct sFunction
{
float (*call)(float f);
const char *name;
};
float foo(float f) { return f / 2.0F; }
float bar(float f) { return f / 2.0F; }
float baz(float f) { return f / 2.0F; }
void test(float (*call)(float), const char *name)
{
static const char *outcome[] = { "Ok", "Error"};
int result = call(rand()) < RAND_MAX / 4.0F;
printf("%s: %s\n", name, outcome[result]);
}
#define BIND(x) {x,#x}
int main(void)
{
size_t i;
struct sFunction table[] = { BIND(foo), BIND(bar), BIND(baz) };
srand(3);
for ( i = 0; i < sizeof table / sizeof *table; ++i )
{
test(table[i].call, table[i].name);
}
return 0;
}
/* my output
foo: Ok
bar: Ok
baz: Error
*/
[/edit]