This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Pointer/Function help

So, I am trying to put together two (rather involved) functions that calculate the DAC. My processing routine for CalcDAC1 and CalcDAC2 are more or less the same, but with different variables. Currently, I'm using global variables that are directly called from the routine. I would like to use the same functionality but send it the variables I want the program to use to process so instead of:

global variables:
unsigned int var1a;
unsigned int var2a;
unsigned int var3a;
unsigned int var1b;
unsigned int var2b;
unsigned int var3b;

void main(void)
{

     while(1)
     {
          CalcDAC1();
          CalcDAC2();
     }
}

void CalcDAC1(void)
{

//Do stuff with var1a
//Do stuff with var2a
//Do stuff with var3a

}

Void CalcDAC2(void)
{

//Do stuff with var1b
//Do stuff with var2b
//Do stuff with var3b

}

I instead would like to do

void main(void)
{

     while(1)
     {
          CalcDAC(var1a, var2a, var3a);
          CalcDAC(var1b, var2b, var3b);
     }
}

void CalcDAC(unsigned char var1, unsigned char var2, unsigned char var3)
{

     //Do stuff with var1
     //Do stuff with var2
     //Do stuff with var3

}

Unfortunately, my particular function has about 7-10 variables (complicated equation with lots of variables) so it requires me to create a LOT of local variables for each iteration, which I don't have the local space for (if that's the right term). Instead, I would like to send it pointers to local variables (if possible).

I ASSUME it would look something like this:

void main(void)
{

     while(1)
     {
          CalcDAC(*var1a, *var2a, *var3a);
          CalcDAC(*var1b, *var2b, *var3b);
     }
}

void CalcDAC(unsigned char *var1, unsigned char *var2, unsigned char *var3)
{

     //Do stuff with var1
     //Do stuff with var2
     //Do stuff with var3

}

Is this correct or is this even possible in C? Is this something you can only do in C++? Any help with implementation you can give me would be greatly appreciated. Thanks!

Parents
  • Both of those are examples of free software that are functional and look good.
    Free??? they are paid for by a charge to the cost of the chips.

    I guess it's not exactly comparing apples to apples. agreed, wrote the above before I read this line

    Like you said, if it's functional, looks don't matter all that much but if you have a good piece of software, it would be nice to have it look updated as well. But I guess your (or someone else's) explanation on further driving up costs makes sense as well. Oh well.
    It really is a case of where you want the developers to use their budget. I, personally, consider using budget (unless you have 'excess') to work on 'look', when you have other things to improve, totally wrong.

    Budgeting 'look' really is a matter of competition and/or "user sophistication". If the competition is equally good and 'looks' a lot better any company will work on it. In some areas of software (specifically what is geared towards the non-sophisticated user) 'look' has a high priority.

    Erik

Reply
  • Both of those are examples of free software that are functional and look good.
    Free??? they are paid for by a charge to the cost of the chips.

    I guess it's not exactly comparing apples to apples. agreed, wrote the above before I read this line

    Like you said, if it's functional, looks don't matter all that much but if you have a good piece of software, it would be nice to have it look updated as well. But I guess your (or someone else's) explanation on further driving up costs makes sense as well. Oh well.
    It really is a case of where you want the developers to use their budget. I, personally, consider using budget (unless you have 'excess') to work on 'look', when you have other things to improve, totally wrong.

    Budgeting 'look' really is a matter of competition and/or "user sophistication". If the competition is equally good and 'looks' a lot better any company will work on it. In some areas of software (specifically what is geared towards the non-sophisticated user) 'look' has a high priority.

    Erik

Children
No data