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.
Add Defines Component; correct syntax
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
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:
and the following is also a valid line:
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.
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};
Code: Select all
rom char *table = "My String";
If you have further problems, try posting your code here and I'll see what's wrong.
-
- Posts: 209
- Joined: Thu Oct 19, 2006 11:46 am
- Location: Bakewell, UK
- Has thanked: 20 times
- Been thanked: 16 times
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?
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.
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
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:
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.
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.