Page 1 of 1

IRQ and C++ ...

Posted: Sat Nov 25, 2006 7:39 am
by xyjamepa
Hi guys...
when i was trying to rewrite my os using C++
and at function "void irq_handler(struct regs *r)"
i got this error:
invalid conversion from 'void*' to 'void (*)(regs*)'
it was working in my c file,and i know its problem about types
i tryied everything but nothing work.

Code: Select all


void *irq_routines[16] =
{
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0
};

void irq_handler(struct regs *r)
{
    /* This is a blank function pointer */
    void (*handler)(struct regs *r);

    /* Find out if we have a custom handler to run for this
    *  IRQ, and then finally, run it */
    handler = irq_routines[r->int_no - 32];
    if (handler)
    {
        handler(r);
    }


    /* If the IDT entry that was invoked was greater than 40
    *  (meaning IRQ8 - 15), then we need to send an EOI to
    *  the slave controller */
    if (r->int_no >= 40)
    {
        outportb(0xA0, 0x20);
    }

    /* In either case, we need to send an EOI to the master
    *  interrupt controller too */
    outportb(0x20, 0x20);
}

i'm using DJGPP and nasm
Thanx.

Posted: Sat Nov 25, 2006 9:22 am
by Tyler
i beleive the problem lies in the line

/* This is a blank function pointer */
void (*handler)(struct regs *r);

and though i not very good at conversion in C as of yet... it clearly reads the first part as void* and it u are converting to a pointer of handle i think it should be handler*... if that conversion is possible.. i am not sure struct can become function pointers.

Then again how can you declare somethign a void and then conver it to a handler... i don't understand that line so you are best ignoring my advice.... except the bit about trying to change it to handler* then some better programmer can come and correct us both :-P

Posted: Sat Nov 25, 2006 9:40 am
by Mikae
The problem is that you declared array of pointers to void, not array of pointers to a function.

If you want an array of pointers to a function, you have to write the following declaration:

Code: Select all

void (*irq_routines[16])(struct regs *r);

Posted: Sat Nov 25, 2006 9:54 am
by Tyler
Mikae wrote:The problem is that you declared array of pointers to void, not array of pointers to a function.

If you want an array of pointers to a function, you have to write the following declaration:

Code: Select all

void (*irq_routines[16])(struct regs *r);
hey i was close in my ramblings... i will be dammed...

Posted: Sat Nov 25, 2006 9:56 am
by gaf
Some time ago there was a quite similar thread in the general programming section (link). Maybe it could also help you with your current problem.
void (*irq_routines[16])(struct regs *r);
Better use a typedef as the C declarator syntax for function-pointers can be quite obscure:

Code: Select all

typedef void (*function)();  // "function" is a datatype 
function stubs[0x20];       // Array of function-pointers
regards,
gaf

Posted: Sun Nov 26, 2006 4:20 am
by xyjamepa
thank you Mikae and all of you guys my IRQ works fine now, :P
i used Mikae advice

Code: Select all

void (*irq_routines[16])(struct regs *r);