Search code examples
cfunction-prototypes

Understanding a C prototype


A function prototype is

int alt_irq_register (alt_u32 id, void* context, void (*isr)(void*, alt_u32));

What does the last part mean? What is the *isr doing?


Solution

  • It is a pointer to a function. You must use a function as parameter of the alt_irq_register function. Example:

    void irq_handler(void *ptr, alt_u32 val) { /* my function */
        /* I'm handling the interupt */
    }
    int alt_irq_register (alt_u32 id, void* context, void (*isr)(void*, alt_u32));
    

    In your code, you must use alt_irq_register function in this way:

    /* your code */
    ret = alt_irq_register(id, context_ptr, irq_handler);
    /* other code */
    

    I am supposing that this function register and interrupt handler, so during the registration you are passing to the system the function that it must uses when the associated interrupt occur.