I cleaned up your code a bit. One of the reasons things weren't printing was that you were mixing printf with Serial.print.
Modified version:
typedef void (* myFunctionPointer) ();
/**
* Using a function pointer in a structure.
*/
typedef struct myObject {
myFunctionPointer functionPointer;
int value;
};
/**
* Passing a function pointer to a function.
*/
void passFunction(myFunctionPointer functionPointer) ;
void passFunction(myFunctionPointer functionPointer) {
/* call our passed function */
functionPointer();
}
void testFunction() {
Serial.println("hello");
}
void testFunction2() {
Serial.println("juhu");
}
myFunctionPointer functionPointers[2];
void setup() {
Serial.begin(115200);
/* pointer to void function with no parameters myFunction */
myFunctionPointer functionPointer = testFunction;
/* call original function */
Serial.print("#1 ");
testFunction();
/* call our new pointer function */
Serial.print("#2 ");
functionPointer();
/* create struct */
myObject Object;
Object.value = 1;
Object.functionPointer = testFunction;
Serial.print("#3 ");
Serial.println(Object.value);
Serial.print("#4 ");
Object.functionPointer();
functionPointers[0] = testFunction;
Serial.print("#5 ");
Serial.println((int) functionPointers[0]);
functionPointers[1] = testFunction2;
Serial.println((int) functionPointers[1]);
/* Creepy! but possible. */
Serial.print("#6 ");
functionPointers[0] ();
Serial.print("#7 ");
functionPointers[1] ();
}
void loop() {
// put your main code here, to run repeatedly:
}
Output:
#1 hello
#2 hello
#3 1
#4 hello
#5 103
96
#6 hello
#7 juhu