IRQ and C++ ...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

IRQ and C++ ...

Post 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.
Tyler
Member
Member
Posts: 514
Joined: Tue Nov 07, 2006 7:37 am
Location: York, England

Post 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
Mikae
Member
Member
Posts: 94
Joined: Sun Jul 30, 2006 1:08 pm

Post 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);
Tyler
Member
Member
Posts: 514
Joined: Tue Nov 07, 2006 7:37 am
Location: York, England

Post 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...
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Post 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
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post 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);
Post Reply