Page 1 of 1

C and flowcode

Posted: Fri Apr 07, 2006 1:59 pm
by manio1
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?

Posted: Mon Apr 10, 2006 9:11 am
by Steve
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:

Code: Select all

char my_function(char x);

char my_function(char x)
{
    char retval;

    retval = x+1;

    return (retval);
}
To access this function, use a 'C' icon within your flowchart with code similar to the following:

Code: Select all

FCV_MYVAR1 = my_function(FCV_MYVAR2);
I hope this helps.

problem with pointer

Posted: Sun May 07, 2006 6:53 pm
by samdel
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

Posted: Mon May 08, 2006 9:10 am
by Steve
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.

const char*

Posted: Sun Jun 25, 2006 5:22 pm
by samdel
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

Posted: Mon Jun 26, 2006 10:16 am
by Steve
I think you should be able to declare a function in a similar way to the following:

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++;
    }
}
Then I you should be able to call this function with your own strings:


Code: Select all

print_LCD(3, 1, "bonjour");

print_LCD(0, 0, string1);
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.

pointers

Posted: Mon Jun 26, 2006 12:30 pm
by samdel
Hi,
Thanks , it's works but if there is only the const char as parameter.
no more parameters, too bad.

Many thanks
Christian