C to C++ Porting Issue

by Codewiz51 November 16, 2008 15:26

Update: Check out my wiki page for the latest download of WinROTT

I've run into an interesting problem with the WinROTT port. WinROTT using structures similar to the following to control single user enemies:

typedef struct  statestruct
{
          byte            rotate;
          short           shapenum;  // a shapenum of -1 means get from ob->temp1
          short           tictime;
          void            (*think) (void *);
          signed char     condition;
          struct  statestruct     *next;
} statetype;

When moving to C++, you need to be aware that the following assignments are allowed in C, but not in C++:

void MyFunc1(int *)
{
    //blah blah blah
}

void MyFunc2(float *)
{
    //blah blah blah
}

statetype s_mine2          = {false,SPR_MINE2,3,MyFunc1,0,&s_mine3};
statetype s_mine1          = {false,SPR_MINE1,3,MyFunc2,0,&s_mine2};

The way I changed the code is to cast everything to a void pointer, and then make sure a cast exists in the function to correct the variable pointer type. There are about 160 of these functions. It turned out to be quite tedious and error prone. If you get on a roll with cut and paste, you are likely to create more problems that you solve.

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