This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C language

Dear sir,

Kindly,  help me with the meaning of this line. I have got it from a reference code to populate pie vector table in 28035.
void (**ptr_vtbl)(void) = (void (**)(void)) PIEVCTTBL;

ptr_tbl[ cnt ] = pie_unused;

cnt is a variable used in for loop & pie_unused is an interrupt function.

Otherwise pls guide me to the right place/topic to look for.

I will be grateful and thanks a lot.

harjeet singh

 

 

  • ptr_vtbl is a function pointer.  The general syntax for declaring a function pointer is:

    returntype (*fptr)(arglist);

    ptr_vtbl can hold function pointers that accept no arguments and return a pointer to void,  such as this one:

    extern void *somefunc(void);

    PIEVCTBL is some other type, and thus not suitable for assignment directly to ptr_vtbl.  We need to cast it.  The cast to the correct type for ptr_vtbl looks like this:

    (void (**)(void))PIEVCTBL

    Putting it all together, this line declares a variable ptr_vtbl, which is a function pointer.  Its initial value is PIEVCTTBL.

    The C standard guarantees that all function pointers can hold any function pointer type without losing bits, but you must cast the value back to the correct type before calling it.