What is (void (**) ()) and how to dial it?

In the inline code, I have to figure out if this line of code is:

*((void (**) ()) 0x01) = c_int01; /* Write the interrupt routine entry */ 

I can understand that you are setting an interrupt vector with the function pointer c_int01 , but I cannot understand what cast means (void (**) ()) . I know the standard function pointer notation (void (*)()) , but not the other.

I tried to reorganize the code so that it looked more readable as follows:

 // header typedef void (*interrupt_handler)(); // prototype of an interruption handler #define INTERRUPT_VECTOR 0x01 #define SET_INTERRUPT_HANDLER( handler ) *((interrupt_handler) INTERRUPT_VECTOR) = (handler) // code SET_INTERRUPT_HANDLER( c_int01 ); 

But the built-in compiler whines about non-object LHS.

Does anyone know what this designation means? (void (**)())

// EDIT:

For those who were interested, I would understand this much better:

 *( (void (*)())* 0x01) = c_int01; 
+4
source share
5 answers

This is a pointer to a pointer to a function.

So, casting converts the integer 0x01 to the address of a function pointer of type (void (*)())

You can rewrite it:

 typedef void (*interrupt_handler)(); *((interrupt_handler*) 0x01) = c_int101; 
+10
source

(void (**) ()) is a pointer to a function pointer.

( (void (*)()) is a pointer to a function, so adding a star adds a level of indirection.)

You need to say:

 *((interrupt_handler*) INTERRUPT_VECTOR) = (handler) 

This reads: "Treat INTERRUPT_VECTOR as a pointer to a pointer to a function and set its value to handler ."

+4
source

Here, which is always useful, cdecl talks about the core of this expression, (void (**) ()) :

type unknown_name in a pointer to the return void function

So, this is casting (indicated by an external pair of parentheses), and the type is "pointer to a pointer to a function", which, apparently, makes sense.

+2
source

Cdecl will be a faster way to find out:

  cast unknown_name into pointer to pointer to function returning void 

The famous "spiral rule" will be as follows:

  +-----+ |+-+ | || | V (void (** |)( )) ^ ^^|| | | |||| | | ||+| | | +--+ | +---------+ 

Following the lines you are reading:

  • pointer to
  • pointer to
  • function returning
  • invalid
+1
source

You can visualize the interrupt entry point vector setting as

  void (*interupt_handlers)()[256] = 0; void set_interupt_handler(int vector, void(*handler)()) { interupt_handlers[vector] = handler; } 
-1
source

All Articles