Created
February 5, 2009 04:06
-
-
Save tbielawa/58545 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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