Macro call directly from a variable
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
- Contact:
Macro call directly from a variable
Is there a way to directly call a macro based on a variable or is using the "switch" function the only way? I have attached a flowchart based on using the switch to hopefully explain what I am trying to do but, Instead of using using switch to determine which macro gets called the variable would directly call the appropriate macro.
- Attachments
-
- macrocall.fcf
- (14.5 KiB) Downloaded 331 times
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
- Contact:
Re: Macro call directly from a variable
There's probably a complicated way to do it in C (pointer to function ?), but what you made is how I'd do it.
There's no way you can call a function just from setting a variable to a specific value.
- Nicolas
There's no way you can call a function just from setting a variable to a specific value.
- Nicolas
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
- Contact:
Re: Macro call directly from a variable
If anyone has any ideas on how to do this I would be very appreciative. I don't care if you idea is in c or asm or uses boostc or HITECH C. I have done a bit of internet searching and have not found a thing. Using the switch function is just taking too many instruction cycles and bloating the size of my code. So basically, x is a number between 0 and 255 and there up to 255 different pieces of code that can be performed. Which piece of code that gets performed depends on what the value of x is. And the kicker is I need the code to be very lean. I can replace the Flowcode switch icon with the boostc switch conditional* but still, if x is say 255 it has to check the value of x 255 times just to get there. Seems like a very inefficient way to do it.
*
switch(FCV_X)
{
case 0:
//my code here
break;
//.........case 1 thru 254 here
case 255:
//my code here
break;
}
*
switch(FCV_X)
{
case 0:
//my code here
break;
//.........case 1 thru 254 here
case 255:
//my code here
break;
}
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: Macro call directly from a variable
Hello.
In C you would do something like:
I'm not sure this is well supported by BoostC though - I doubt it. I hope this gives you something to go on.
Jonny
PS: You could probably get FCv6 to do something like this using properties, but not v5 or below.
In C you would do something like:
Code: Select all
// Type of function to be calling
typedef int (PROTOTYPE)(int Arg);
// Function definitions
int Func1(int Arg) { return Arg + 1; }
int Func2(int Arg) { return Arg + 2; }
// Lookup table of functions
static const PROTOTYPE Callbacks[] = {
&Func1,
&Func2
}
// Call the function
result = Callbacks[index](57);
Jonny
PS: You could probably get FCv6 to do something like this using properties, but not v5 or below.
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
- Contact:
Re: Macro call directly from a variable
I needed to revisit this problem for another project but needed a faster way to do it (vs using switch) and also I needed the length of time to determine the value of the variable to be more consistent. When using switch the length of time to determine the value increases as the value increases. I thought I would share a simple solution in case anyone else needs this feature.
- Attachments
-
- determine_value_of_variable_by_anding.fcf
- (13.7 KiB) Downloaded 295 times