Page 1 of 1

Porting JamesM's tutorials to c++, ran into 1 issue.

Posted: Tue Jun 08, 2010 10:37 pm
by astrocrep
So I have been going through the usermode tutorial, and changing things to make it compile in g++ 4.5 (cross)

I've fixed a bunch of stuff, but I am not sure about the following...

I am trying to initialize an array:

Code: Select all

static void *syscalls[3] =
{
    &monitor_write,
    &monitor_write_hex,
    &monitor_write_dec,
};
Where those three functions are:

Code: Select all

void monitor_write(char *c);
void monitor_write_hex(u32int n);
void monitor_write_dec(u32int n);
However g++ is throwing the following errors...

Code: Select all

error: invalid conversion from 'void (*)(char*)' to 'void*'
error: invalid conversion from 'void (*)(u32int)' to 'void*'
error: invalid conversion from 'void (*)(u32int)' to 'void*'
I have tried a couple of different things, but I am getting the feeling this might be illegal in c++...

Hopefully I am just missing something obvious.

Thanks in advance,
Rich

Re: Porting JamesM's tutorials to c++, ran into 1 issue.

Posted: Tue Jun 08, 2010 11:48 pm
by Combuster
The standard says that functions may not be converted to variables and vice-versa. Declare syscall as a function array.

Re: Porting JamesM's tutorials to c++, ran into 1 issue.

Posted: Wed Jun 09, 2010 12:07 am
by rknox

Re: Porting JamesM's tutorials to c++, ran into 1 issue.

Posted: Wed Jun 09, 2010 4:43 am
by Creature
Combuster wrote:The standard says that functions may not be converted to variables and vice-versa. Declare syscall as a function array.
Or... a bit more hacky: cast all function addresses to void pointers.

Re: Porting JamesM's tutorials to c++, ran into 1 issue.

Posted: Wed Jun 09, 2010 5:48 am
by astrocrep
Thanks guys... thats what I was looking for.