Is it possible to use functions in the c block of flowcode? when i try to declare
a function it doesn't compile. cives me c error.
Any ideas?
C and flowcode
- Steve
- Matrix Staff
- Posts: 3424
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
The 'C' icon actually puts any 'C' code within a function body, which is why a function declaration will cause a 'C' error.
To overcome this, use the "#defines" component to add a block of 'C' code that gets put near the start of the 'C' code, outside of any functions.
Here's a quick example. Put this into a #define component:
To access this function, use a 'C' icon within your flowchart with code similar to the following:
I hope this helps.
To overcome this, use the "#defines" component to add a block of 'C' code that gets put near the start of the 'C' code, outside of any functions.
Here's a quick example. Put this into a #define component:
Code: Select all
char my_function(char x);
char my_function(char x)
{
char retval;
retval = x+1;
return (retval);
}
Code: Select all
FCV_MYVAR1 = my_function(FCV_MYVAR2);
problem with pointer
Hi,
I had a error message : a function cannot have a pointer as a parameter
because I would like to use a function finded , and the beginning of it is :
print_LCD(char cX, char cY, char *chaine)
Is it possible to solve my problem ?
thank you in advance
bests regards
Christian
I had a error message : a function cannot have a pointer as a parameter
because I would like to use a function finded , and the beginning of it is :
print_LCD(char cX, char cY, char *chaine)
Is it possible to solve my problem ?
thank you in advance
bests regards
Christian
- Steve
- Matrix Staff
- Posts: 3424
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
In FlowCode v2, the underlying 'C' compiler does not support pointers in this way, so what you are trying to achieve is not possible. If you do not want to change the "chaine" variable within your function, you can declare it as a "const char*" (which would allow you to pass an array to the function instead).
The next version of FlowCode (v3) will use a better 'C' compiler which has much better support for pointers.
The next version of FlowCode (v3) will use a better 'C' compiler which has much better support for pointers.
const char*
hello,
I would like to call a function and pass to it a string ("Vitesse" for example) as a parameter
If I declare : const char *vit = "Vitesse du vent"; within the function , it's OK I can use it , but I would like this to be a parameter because I would like to use the same function for others 'const char'
Is it possible ?
Thank you to help me
Bests regards
Christian
I would like to call a function and pass to it a string ("Vitesse" for example) as a parameter
If I declare : const char *vit = "Vitesse du vent"; within the function , it's OK I can use it , but I would like this to be a parameter because I would like to use the same function for others 'const char'
Is it possible ?
Thank you to help me
Bests regards
Christian
- Steve
- Matrix Staff
- Posts: 3424
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
I think you should be able to declare a function in a similar way to the following:
Then I you should be able to call this function with your own strings:
Hopefully, this will do what you want. FlowCode v3 is very close to completion and this will give you much more flexibility. You will be able to use strings within FlowCode itself without needing to generate C code. Or if you prefer to embed your own C, the compiler used will allow you to use pointers and arrays is a much better way than the restrictions imposed by the C2C compiler.
Code: Select all
void print_LCD(char cX, char cY, const char *chaine);
void print_LCD(char cX, char cY, const char *chaine)
{
char idx = 0;
while (chaine[idx] != 0)
{
//do something with each character here...
idx++;
}
}
Code: Select all
print_LCD(3, 1, "bonjour");
print_LCD(0, 0, string1);
pointers
Hi,
Thanks , it's works but if there is only the const char as parameter.
no more parameters, too bad.
Many thanks
Christian
Thanks , it's works but if there is only the const char as parameter.
no more parameters, too bad.
Many thanks
Christian