C and flowcode

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
manio1
Posts: 6
Joined: Wed Nov 30, 2005 2:05 pm
Contact:

C and flowcode

Post 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?

User avatar
Steve
Matrix Staff
Posts: 3424
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post 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.

samdel
Posts: 7
Joined: Sun May 07, 2006 6:46 pm
Contact:

problem with pointer

Post 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

User avatar
Steve
Matrix Staff
Posts: 3424
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post 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.

samdel
Posts: 7
Joined: Sun May 07, 2006 6:46 pm
Contact:

const char*

Post 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

User avatar
Steve
Matrix Staff
Posts: 3424
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post 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.

samdel
Posts: 7
Joined: Sun May 07, 2006 6:46 pm
Contact:

pointers

Post 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

Post Reply