Page 1 of 1

C Box declarations for "long" or "short"

Posted: Tue Sep 07, 2010 4:19 pm
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

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

Posted: Tue Sep 07, 2010 4:46 pm
by medelec35

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

Posted: Wed Sep 08, 2010 11:53 am
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

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

Posted: Fri Sep 10, 2010 3:43 pm
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);

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

Posted: Mon Sep 13, 2010 12:58 pm
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