porting a c function to c++

C

cfn

Hi,

I want 2 port a cfunction to c++.

My question is that I do not know how to handle the arrays in the
parameterlist in the following function. (int imins[2][2],jmins[2][2];)

Can someone please tell me how to write this in a c++ manner?
To be more exact: how do I handle the static arrays in the
parameterlist?

regards
Christofer


.....
static void frame_estimate(org,ref,mb,i,j,sx,sy,
iminp,jminp,imintp,jmintp,iminbp,jminbp,dframep,dfieldp,tselp,bselp,
imins,jmins)
unsigned char *org,*ref,*mb;
int i,j,sx,sy;
int *iminp,*jminp;
int *imintp,*jmintp,*iminbp,*jminbp;
int *dframep,*dfieldp;
int *tselp,*bselp;
int imins[2][2],jmins[2][2];
{
int dt,db,dmint,dminb;
int imint,iminb,jmint,jminb;

/* frame prediction */
*dframep = fullsearch(org,ref,mb,width,i,j,sx,sy,16,width,height,
iminp,jminp);
.....
 
O

osmium

cfn said:
Hi,

I want 2 port a cfunction to c++.

If you can't find time in your busy day to write a question, why in God's
name do you think we can find time to answer it??

<SNIP>
 
T

Tomás

static void frame_estimate(org,ref,mb,i,j,sx,sy,
iminp,jminp,imintp,jmintp,iminbp,jminbp,dframep,dfieldp,tselp,bselp,
imins,jmins)
unsigned char *org,*ref,*mb;
int i,j,sx,sy;
int *iminp,*jminp;
int *imintp,*jmintp,*iminbp,*jminbp;
int *dframep,*dfieldp;
int *tselp,*bselp;
int imins[2][2],jmins[2][2];
{
int dt,db,dmint,dminb;
int imint,iminb,jmint,jminb;

/* frame prediction */
*dframep = fullsearch(org,ref,mb,width,i,j,sx,sy,16,width,height,
iminp,jminp);


namespace {

void frame_estimate(unsigned char *org, unsigned char *ref, unsigned char
*mb, int i, int j,
int sx, int sy, int *iminp, int *jminp, int *imintp,int *jmintp,int
*iminbp,int *jminbp,
int *dframep,int *dfieldp,int *tselp,int *bselp, int imins[2][2], int
jmins[2][2] )
{
return;
}

}


-Tomás
 
P

Puppet_Sock

cfn said:
I want 2 port a cfunction to c++.

Tomás has answered your specific question. All you really *need*
to do is change from the very old style parameter list to the new
style parameter list, then carry on as usual.

[snip]
static void frame_estimate(org,ref,mb,i,j,sx,sy,
iminp,jminp,imintp,jmintp,iminbp,jminbp,dframep,dfieldp,tselp,bselp,
imins,jmins)
unsigned char *org,*ref,*mb;
int i,j,sx,sy;
int *iminp,*jminp;
int *imintp,*jmintp,*iminbp,*jminbp;
int *dframep,*dfieldp;
int *tselp,*bselp;
int imins[2][2],jmins[2][2];
{

So all you really need to do here is get each of those things after the
closing ) up into the ( ) list.

Now, if all you want to do is get some legacy code to run under your
shiny new C++ compiler, that is probably enough. And if that's all
you care about, the rest of this post is probably a waste of your time.
(Oh, you probably don't want the keyword static.)

But! If you want to do some work you can make a much better
program. For example, this function makes me think that a class
called frame with a member function called estimate are good
candiates. Then many of those parameters could become
data members of the class and get removed from the param
list. 19 parameters to a function is probably too many. If
it was a class, you might be able to have this function have
as few as two parameters, and possibly return the result
as the function's return value instead of through one of
its arguments. (I'm guessing that a function called estimate
is not *just* called for side effects.)

So, if you have the budget for a restructuring, you might find that
you can improve your code a lot by doing more than a simple
porting. But before you jump at that, it would be a *lot* of work.
Socks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top