Arrays of function pointers
I've been programming in C since the early 1980's, before C++ was invented.
Back then computers weren't as fast as they are now so we had to make every line of code work hard. Did you know you can execute one element in an array of function pointers ? I use the tiny-C compiler so this is an entire program and cleanly compiles to a 1,536 byte executable.
Here is some code for you to chew on (take this code and run with it);
See if you can determine it's output before you compile & run it.
int fn1(int), fn2(int);
int i = 0;
fnptr = &fn1;
fnptr = &fn2;
int fn1(int i)
printf("Hello world fn1 got %d!\n",i);
int fn2(int i)
printf("Hello world fn2 got %d!\n",i);
If you put the functions before the main, you don't need the function declarations. We removed much of the white space to save on file size, it was an issue back then. We recognized ram in kilobytes, megabytes weren't really invented yet. :D I'm pretty sure you didn't want one long line. :D
It's elegant in its simplicity. When I had thousands of functions to fulfill, I would write a program that would write the program I compiled. I could take 2 days writing the program or 2 hours writing a program that would write the program for me.:cool: