Jump to content
Sign in to follow this  
jonathan03

Function Calls With Arguements Of Two Functions

Recommended Posts

Bug description:

If a fucntion is called with arguements of two or more other functions that return a value, the same value is used for all parameters.

 

Steps to reproduce:

unsigned char MyFunctionOne()
{
    ...........
    return 2;
}

unsigned char MyFunctionTwo()
{
    return 17;
}

void TwoParameterFunction(unsigned char one, unsigned char two)
{
   ....... any code
}

void main()
{

   TwoParameterFunction(MyFunctionOne(), MyFunctionTwo());
   //instead of TwoParameterFunction(2,17); what happens is 
   //TwoparameterFunction(2,2);

  /*
  //the fix
  usigned char tmp;

  tmp = MyFunctionTwo();
  TwoparameterFunction(MyFunctionOne(), tmp);
  */

}

 

Expected behaviour:

Should be able to call a function with arguements that are the result of two other functions.

 

Is the problem 100% reproduceable:

Happens all the time.

 

IDE version: 6.15

Compiler: BoostC

Compiler version: 6.15? (Not sure how to tell)

Target device: PIC16F628

OS: Windows XP

 

Comments:

I think that the problem is that the compiler puts the result of a function call in the working register (w). There doesn't seem to be logic to store one of the values to a temporary register. From the assembly code, it looks like all return values are put in w.

 

Also, this code results in a bug too.

 

MyArray[MyFunctionOne()] = TwoParameterFunction(MyFunctionOne(), MyFunctionTwo());

//is the same as
//MyArray[2] = TwoParameterFunction(2, 2);




//and
MyArray[MyFunctionOne()] = OneParameterFunction(MyFunctionOne());

//is the same as
//MyArray[2] = TwoParameterFunction(2);

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...