Calling a variable function

I need to call a function inside of a function like the attach Interrupt function.

attachInterrupt(0, blink, CHANGE);

I'm making an alarm but the alarm isn't the first priority so i can't just use and loop. So I need to call something like blink, How could i do this?

The attachInterrupt function does not call the blink function. It sets up an interrupt vector that calls the specified function when the specified change happens on the specified pin.

It is not clear how attachInterrupt relates to what you are trying to do.

Can you clarify?

If you want to pass the name of a function to call to another function, like you pass blink to attachInterrupt, that is not too difficult. The argument is a pointer to a function. The signature of function that can be passed needs to exactly match the signature specified in the caller function's definition.

I'm trying to call a specified function in a function (I was just using attachInterrupt as a example) how could i call a function like that?

The alarm i'm making will check if it is passed that specified time and if it is it calls the function specified in createAlarm(time,function to call).

I'm trying to call a specified function in a function

You need a function pointer.

Have a look at the declaration of functions like "attachInterrupt" for ideas and syntax.

I tried looking for the declaration but i couldn't find it, where would it be?

The declaration for attachInterrupt is in wiring.h, and looks like:

void attachInterrupt(uint8_t, void (*)(void), int mode);

The definition for attachInterrupt is in WProgram.cpp, and looks like:

void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)

What it says is that the function that is passed to attachInterrupt has a signature like:

void blink()
{
}

If your function takes no arguments, and returns no value, you can use the same signature for the function as attachInterrupt. Specifying a function that takes arguments and/or returns a value is more complicated.

I hate asking too many questions,(Its too late for that) but i cannot find WProgram.cpp. I found WProgram.h but its isnt useful, Where is it?

Sorry. That should be WProgram.c, not .cpp, for Arduino 0017. For Arduino 0018, the function moved to WInterrupts.c.

Yay found it! Thanks Paul.