Jack Golma Jack Golma - 1 year ago 78
C Question

What's the meaning of this part of code?

Can somebody say what's the meaning of this code?

void (* const rvt[])(void) = {
(void (*) (void))((unsigned long)&__STACK_END), // The initial stack pointer
xkg_som, // The reset handler
xnt_ISR, // The NMI handler
FaultISR, // The hard fault handler
IntDefaultHandler, // The MPU fault handler
bgs_stm, // The bus fault handler
IntDefaultHandler, // The usage fault handler
0, // Reserved
0, // Reserved
IntDefaultHandler, // The MPU fault handler

I actually don't understand it.

Answer Source
void (* const rvt[])(void)

Means (courtesy of cdecl.org):

declare rvt as array of const pointer to function (void) returning void

T foo = {
    value3 // ...

This is copy-list-initialization[6] of the array. Furthermore, this means that the declaration of rvt is a definition.


The addresof operator takes the memory address of the variable.

(unsigned long)&__STACK_END)

The address is casted to unsigned long type.

(void (*) (void))((unsigned long)&__STACK_END)

The converted value is again casted to pointer to function (void) returning void, which is the type of function pointers stored in the array.

The rest of the initialized values of the array are either function names, function pointers or something that can be implicitly converted to a function pointer such as lambdas.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download