Some notes on porting WinROTT to C++

by Codewiz51 July 15, 2008 22:12

I am in the process of porting the file rc_actor.c to rc_actor.cpp for the game Rise of the Triad (see my progress page). I had forgotten how flexible (or loose) C is compared to C++.

The difference in type checking between C and C++ can be maddening when porting simple function pointers:

In C, you can declare a function pointer as:

void (think *) (void *);

and

void gettarget(objtype *);

You can then assign:

think = gettarget;

In C++, you must declare gettarget as

void gettarget(void * tob)
{
    // Must assign ob to tob
    // tob is the void*, cast to objtype*
    objtype * ob = tob;
....
}

If you do not, then you will see the following error:

error C2440: '=' : cannot convert from 'void (__cdecl *)(void *)' to 'void (__cdecl *)(objtype *)'

Converting the function calls, and handling any code changes neccessary for casting void* to objtype* is very tedious. I'm down to about 75 errors in my work with rt_actor.cpp. I certainly hope it all works after I complete the port. Surprised

Tags: , ,

WinROTT

Comments are closed

Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen | Modified by Mooglegiant

Disclaimer

This blog represents my personal hobby, observations and views. It does not represent the views of my employer, clients, especially my wife, children, in-laws, clergy, the dog, the cats or my daughter's horse. In fact, I am not even sure it represents my views when I take the time to reread postings.

© Copyright 2008-2011