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

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
astrocrep
Member
Member
Posts: 127
Joined: Sat Apr 21, 2007 7:21 pm

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

Post 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
Mouse Pad - Coming in the distant future...
Kernel: Indigo Kernel - v0.0.1

Thanks to JamesM and BrokenThorn for there tutorials!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post by Combuster »

The standard says that functions may not be converted to variables and vice-versa. Declare syscall as a function array.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

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

Post 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.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
User avatar
astrocrep
Member
Member
Posts: 127
Joined: Sat Apr 21, 2007 7:21 pm

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

Post by astrocrep »

Thanks guys... thats what I was looking for.
Mouse Pad - Coming in the distant future...
Kernel: Indigo Kernel - v0.0.1

Thanks to JamesM and BrokenThorn for there tutorials!
Post Reply