kelvSYC <> wrote:
# Can variable functions be implemented in C, and if so, how?
Yes.
# Also, can you have a function or a function prototype as a member in a
# structure?
Yes.
(cd /tmp
cat <<':eof' >t.c
#include <stdio.h>
#include <stdlib.h>
typedef int (*func)(char *s);
typedef struct {func f; char *s;} object;
int X(char *s) {printf("X-%s-X\n",s); return 1;}
int Y(char *s) {printf("Y-%s-Y\n",s); return 2;}
object choose(char *s) {
object o; o.s = s;
switch (*s) {
case 'x': o.f = X; break;
case 'y': o.f = Y; break;
}
return o;
}
int apply(object o) {return o.f(o.s);}
int main(int N,char **P) {
int r = apply(choose(P[1]));
printf("return %d\n");
return 0;
}
:eof
cc t.c
a.out xyzzy)
X-xyzzy-X
return 0
--
Derk Gwen
http://derkgwen.250free.com/html/index.html
But I do believe in this.
--
comp.lang.c.moderated - moderation address: