Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In an embedded code I have to understand, there's this line of code :

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

I can grasp the fact that you setup the interruption vector with the function pointer c_int01, but I can't figure what kind of cast (void (**) ()) refers to. I know the standard function pointer notation (void (*)()) but not the other one.

I tried to refactor the code so that it looked a bit more readable like this:

// 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 embedded compiler whines about the LHS not beeing an object.

Anybody know what this notation signifies? (void (**)())

// EDIT:

For those interrested, I would understand this much better:

*( (void (*)())* 0x01) = c_int01;
like image 650
Gui13 Avatar asked Dec 05 '22 11:12

Gui13


1 Answers

It's a pointer-to-pointer-to-function.

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

You could rewrite it:

typedef void (*interrupt_handler)();
*((interrupt_handler*) 0x01) = c_int101;
like image 108
Steve Jessop Avatar answered Dec 30 '22 11:12

Steve Jessop