Add Defines Component; correct syntax

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

Moderators: Benj, Mods

Post Reply
Mark
Posts: 209
Joined: Thu Oct 19, 2006 11:46 am
Location: Bakewell, UK
Has thanked: 20 times
Been thanked: 16 times
Contact:

Add Defines Component; correct syntax

Post by Mark »

Hi,

I am starting to use the Add Defines component in Flowcode 3 and seem to be generating all sorts of compilation errors depending upon how the data is defined, though the errors are not related to the data lines themselves.

I can probably work it through myself, but some pointers would help:

In a previous post (on v2.2) the following code works fine

Defines component (called in a flowcode macro)

const char table[] = {1,2,3,4};

and retrieval of the table values in a further C block.

FCV_DATA = table[FCV_INDEX];

Steve pointed out that 'rom' should replace 'const' in v3 as this is BoostC. (though const seems to work also in Flowcode 3), it just seems to generate a load W and compare table rather than RETFIE instructions).

However:

The boost C manual requires the defines coding as

rom char *table = {1,2,3,4};

however the * seems optional (what does it do?)
You will also see that there are no square btackets [].

for strings Boost C requires

rom char *table = "My String";

does this port to Flowcode? If so should I call the string data back into flowcode with a byte variable or a string variable type? The array is a char (byte array), but the data is string data?

I have tried many combinations of features but when compiled to assembler various errors appear (not least 'missing semicolon' where the line the error is on a line clearly having a semicolon).

Any general pointers as to how to read the BoostC manual when using the Defines component will help.

Thanks again.
Go with the Flow.

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

Post by Steve »

Hello Mark,

Firstly, I'd suggest using the "Supplementary code" feature of Flowcode V3 instead of the "Add defines" component - they do exactly the same thing. The "add defines" component has been retained for backwards compatibility only.

The following two lines are identical as far as 'C' is concerned:

Code: Select all

rom char *table = {1,2,3,4};
rom char table[] = {1,2,3,4}; 
and the following is also a valid line:

Code: Select all

rom char *table = "My String";
When you get "missing semicolon" errors, they generally refer to the line after the error, so you should look just before the line indcated to see where the problem is.

If you have further problems, try posting your code here and I'll see what's wrong.

Mark
Posts: 209
Joined: Thu Oct 19, 2006 11:46 am
Location: Bakewell, UK
Has thanked: 20 times
Been thanked: 16 times
Contact:

Post by Mark »

Hi Steve,

Once again, many thanks for your reply.

I have now got the tables of values working fine. At least when coded as part of the main flowcode loop. After getting the tables working and outputting various messages via RS232 I then copied the code to a Macro, so as to clear the desk so to speak and work on the next part of the coding.

After copying to a Macro (I did a straight cut and paste) various errors came up when compiling. I did not change any of the variables to local variables or pass any parameters when setting up the Macro.

Coding used (cut down example)

Supplementary code
rom char *table = {1,2,3,4,5,6,7,8,9};

C code (in a loop)
FCV_VALUE = table [FCV_INDEX];
FCV_INDEX = FCV_INDEX + 1;

Complies fine but when in a Macro gives :

C:\Documents and Settings\User\Desktop\Temporary\Dump\macro table.c(80:14): error: unknown identifier 'table'
C:\Documents and Settings\User\Desktop\Temporary\Dump\macro table.c(80:14): error: failed to generate expression
C:\Documents and Settings\User\Desktop\Temporary\Dump\macro table.c(80:14): error: invalid operand 'table [FCV_INDEX]'
C:\Documents and Settings\User\Desktop\Temporary\Dump\macro table.c(80:12): error: failed to generate expression

What is the underlying issue?
Go with the Flow.

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

Post by Steve »

It could be the space between "table" and "[FCV_INDEX]" it deosn't like. If that doesn't work, please send me your FCF file and I'll have a look.

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

Post by Steve »

Having seen your FCF file, i can see what the problem is. You need to put the "rom char* table" bit into the "Definitions and function declarations:" part of the supplementary code, rather than the "Function implementations:" part.

The reason for these 2 boxes is due to the nature of C. In C, variables and functions (etc) are only "visible" to the portions of the C file *after* the position where they are declared.

The C file that is generated by Flowcode v3 is split up into the following sections:
  • 1 Internal definitions
    2 Macro function declarations
    3 Variable declarations
    4 Supplementary defines
    5 Macro implementations
    6 Supplementary implementations
    7 Main function


Note that all sections up to 5 are for definitions only – these will define all global variables, constants and functions. After that come the functions themselves (“implementations”).

Your program that did not work had the definition for “table” in section 6 – after the implementations of your macro. This meant that your macro could not “see” the definition of “table”.

Splitting the definitions and implementations in this way allows all macros/functions to “see” all definitions (including the definitions of the other macros).

I hope this explanation helps.

Post Reply