Run function from another function?

Hi, I want to be able to run a function from another function. I would like to be able to do something like this.

void setup(){

Serial.begin(9600);

}

void loop(){

runFunction(someStuff);

}



void runFunction(void Function){

Function();

}


void someStuff(){

Serial.println("Hi");

}

How would I go about doing this? Sorry if this is a really nooby question...

Google "C function pointers"

Make the function argument either a reference or pointer.

Reference:void runFunction(void (&Function)())

Pointer:

void runFunction(void (*Function)())
{
  (*Function)();
}

The reference way requires fewer changes.

johnwasser:
Pointer:

void runFunction(void (*Function)())

{
 (*Function)();
}

The pointer way can be written like this:

void runFunction(void (*Function)())
{
  Function();
}

There's no need to dereference a function pointer before calling it.

Wow thanks for the help. Much more simple than I expected. One more thing. As Im trying to use this for a library, Would I need to (and how) assign the function to another variable again in the class?

class NBDelay
{
 public:
 NBDelay(void (&Function)(), int time);
 void check();
 private:
 int pMillis(), int Time;
 void (&Function2)() = Function;
};

Not sure if the void (&Function2)() = Function; part would work or not...

Not sure if the
Code: [Select]

void (&Function2)() = Function;

part would work or not...

It will not. Re-read the first reply. The word pointer was in there for a reason.

If you want a function to store the address of the other function to be called later, definitely use a pointer.

class NBDelay
{
 public:
 NBDelay(void (*Function)(), int time);
 void check();
 private:
 int pMillis(), Time;
 void (*Function2)();
};

Cool. Thanks for the help.