Skip to content

Instantly share code, notes, and snippets.

@tbielawa
Created February 5, 2009 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbielawa/58545 to your computer and use it in GitHub Desktop.
Save tbielawa/58545 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#define MAX_FUN_LEN 8
int foo();
int bar();
struct func_list {
int (*function)();
char fname[MAX_FUN_LEN];
struct func_list *next_function;
int tail;
} ;
int main( int argc, char *argv[]) {
printf("hi 2 u\n");
//Construct the list elements
struct func_list foofunc;
foofunc.function = foo;
strncpy(foofunc.fname, "foo\0", 4);
struct func_list barfunc;
barfunc.function = bar;
strncpy(barfunc.fname, "bar\0", 4);
//barfunc.next_function = "";
// Link the list together now
foofunc.next_function = &barfunc;
printf("foofunc struct has name: '%s'\nwith length: %d", foofunc.fname, strlen(foofunc.fname));
printf("next struct is: '%s'\n", foofunc.next_function->fname);
printf("The nasty pointer in bar is: '%p'\n", barfunc.next_function);
printf("now to run some pointered functions\n\n---\n\n");
foofunc.function();
foofunc.next_function->function();
return 0;
}
int foo() {
printf("--foo--\n");
return 77;
}
int bar() {
printf("--var--\n");
return 77;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment