Home > Back-end >  What does void (* const ivt[])(void) mean?
What does void (* const ivt[])(void) mean?

Time:05-20

I'm reading the book Embedded Systems Architecture by Daniele Lacamera. In Chapter 4,The Boot-Up code

__attribute__ ((section(".isr_vector"))) void (* const ivt[])(void) =
{
    (void (*) (void))(END_STACK),
    isr_reset,
    //...
};

I don't understading void (* const ivt[])(void), is it the array? If it's the array what does (void) mean?

CodePudding user response:

Install the tool cdecl and ask it to explain things to you:

mrvn@ryzen:~$ cdecl
Type `help' or `?' for help
cdecl> explain void (* const ivt[])(void)
declare ivt as array of const pointer to function (void) returning void

CodePudding user response:

It is an array named ivt holding constant pointers to functions that take no parameters and return void.

CodePudding user response:

i dot't understading void (* const ivt[])(void), is it the array?

Yes, ivt is an array of constant pointers to function that accepts no arguments and returns nothing.

The type of elements of ivt array is

 void (* const)(void)

which means constant pointer to function which accepts no arguments and returns nothing.

If it's the array what does (void) mean?

It means function accepts no arguments.

CodePudding user response:

ivt is an array of constant pointers to functions that takes no parameters and have the return type void.

Perhaps an example might help understand the situation better:

void func1()
{
    std::cout<<"func1 called"<<std::endl;
}
void func2()
{
    std::cout<<"func2 called"<<std::endl;
}
void foo()
{
    std::cout<<"foo called"<<std::endl;
}

void foobar()
{
    
}
int main()
{
//----------------vvv---------------------------------> ivt is an array of const pointers to a function with return type of void and having 0 parameters
    void (* const ivt[])(void) = {func1, func2, foo};  
//--------------------------------^^^^^--^^^^^--^^^---> add pointers  to these 3 functions into the array 


   //iterate through the elements in the array and call the member functinos 
   for(void (*const PTR)(void): ivt)
   {
       PTR();
       
//-----------v---------------------------------------->this assignment won't work because pointers are themselves const so you can make them point to another function
       //PTR = foobar; 
   }
    
}
  •  Tags:  
  • c c
  • Related