C Box declarations for "long" or "short"

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Huib Koppers
Posts: 63
Joined: Fri Oct 12, 2007 5:13 pm
Location: Netherlands
Been thanked: 1 time

C Box declarations for "long" or "short"

Post by Huib Koppers »

Hello,

Is het possible to make new variable declarations for other formats then standard supported by FC v4 for example;

"long int" 32bits

"short int" 16bits

If yes how can I do this in the C-Box ?

regards

Huib

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: C Box declarations for "long" or "short"

Post by medelec35 »

Martin

Huib Koppers
Posts: 63
Joined: Fri Oct 12, 2007 5:13 pm
Location: Netherlands
Been thanked: 1 time

Re: C Box declarations for "long" or "short"

Post by Huib Koppers »

Hello medelec,

BoostC does not make part of the ARM and AVR directory.

It could be helpfull if there is a document for FCv4 to ARM and AVR how to implement non standard variables and functions in C code into the C-Box so that compiling it without errors for users who are not so advanced and familiar with C Code.
Also there will be not unnessesary questions made on this forum so that you all can spent more time on more important questions for advanced users.

Is that an option ?

regards Huib

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: C Box declarations for "long" or "short"

Post by Benj »

Hello Huib,

The following should work for almost any embedded C compiler though don't quote me on that one :P

32-bit variables
signed long x;
unsigned long x;

16-bit variables
signed int x;
unsigned int x;
short x;

NB: shorts are normally exactly the same as "signed int" variables.

8-bit variables
signed char x;
unsigned char x;
char x;

NB: chars are normally exactly the same as "unsigned char" variables.

Signed variables can go negative and unsigned variables are positive only.

16-bit Unsigned is 2 to the power 16 so 0 to 65535
16-bit signed is 2 to the power 16 with 0 being in the middle of the range so -32768 to 32767

Covering all the basics of C in a single document would be fairly tricky and time consuming and is not likely to generate any sales so its probably not worth us doing this unless there is a big demand for such a thing from our customers.

When working with long variables it is normally worthwhile doing a type cast or the compiler will normally default to a 16-bit calculation. To type cast you would do something like this.

Code: Select all

unsigned long var1;
var1 = (unsigned long) 158 * 25;
Basically just putting the variable type in brackets after the equals sign but before the calc.

Here is how it is used in the FAT routines when handling 32-bit variables.

Code: Select all

root_size = Read_Byte_From_Buffer(0x24);	//Size of root directory x 32 byte file/directory entries
root_size = root_size | ( Read_Byte_From_Buffer(0x25) << 8);
root_size = root_size | ((long)  Read_Byte_From_Buffer(0x26) << 16);
root_size = root_size | ((long)  Read_Byte_From_Buffer(0x27) << 24);

Huib Koppers
Posts: 63
Joined: Fri Oct 12, 2007 5:13 pm
Location: Netherlands
Been thanked: 1 time

Re: C Box declarations for "long" or "short"

Post by Huib Koppers »

Hello Benj,

Thanks for your reply,

This gives me a better understanding how C things about variables and declarations can be implemented in FlowCode.

I'm just a hobbyist and held MM not responsible for any comment, but sometimes it can be that i have some questions which are very importand for me.
Fortunately I'm not so familiar with C and only want to learn about this and how it is done in C by syntax writing.

So the examples you have mentioned are a big help for me.

Thanks a lot

Regards

Huib

Post Reply