Bugs and Gotchas
The Control-C cross-compiler was written by Fabius Software Systems and customized by Mosaic Industries to facilitate programming Mosaic embedded controllers in C. To program in C, use the IDE (Integrated Development Environment) based on the TextPad editor to create your source code program files. Clicking in the Terminal window and sending the download file to the 68HC11 microcontroller via the RS-232 serial link completes the process: you can then type main from your terminal to execute your program. This page summarizes known bugs.
Nested Arrays
When nesting arrays in C, like values[sort[i]], fabius ignores the outer array and simply returns the value of the inner array. See the following example.
The output should be:
Values unsorted: 42 2034 99 12 59 Values sorted: 12 42 59 99 2034 The smallest number is 12
The actual output is:
Values unsorted: 42 2034 99 12 59 Values sorted: 3 0 4 2 1 The smallest number is 12
And finally here is the code:
int sort[5]; int values[5]; main( void ) { int i; sort[0] = 3; sort[1] = 0; sort[2] = 4; sort[3] = 2; sort[4] = 1; values[0] = 42; values[1] = 2034; values[2] = 99; values[3] = 12; values[4] = 59; printf("Values unsorted:\n" ); for( i=0;i<5;i++ ) { printf( "%d\n", values[i] ); // WORKS } printf("\nValues sorted:\n"); for( i=0;i<5;i++ ) { printf( "%d\n", values[ sort[i] ] ); // NOT WORKING } printf( "\nThe smallest number is %d\n", values[ sort[0] ] ); // WORKS }
Note that passing a constant in to a nested array is fine.
tmp = sort[i]; printf( "%d", values[tmp] );
printf() and sprintf() floating point and fixed point notation display error
When using fixed point notation the function printf prints the minus sign for a negative number on the far left of the field while right justifying the rest of the number, inserting spaces between the minus sign and the number. Similarly, it doesn't right justify the minus sign on a floating point number when all of the width is not used, instead printing the minus sign on the far left.
For example,
printf("\n%7.2f",-3.12);
prints
- 3.12
instead of
-3.12
We can work around this bug by first writing to a string and then correcting the string before printing it, as,
char tempstring[20]; sprintf(tempstring,"%6.2f",-3.12); if (tempstring[0]=='-' && tempstring[1]==' ') { *strrchr(tempstring,' ')='-'; tempstring[0]=' '; } printf("%s",tempstring);
printf() rounding error
printf() appears to display a rounding error that depends on the number of places to the right of the decimal point specified in the command. It produces an error equal to one tenth of the value of the last decimal place. That is, if the number of places is n, the error is:
|error| = 10-(n+1)
For numbers whose absolute value is much greater than the least significant digit displayed the error is not important, but for numbers whose value is comparable the error can be profound.
Filenames Beginning with numbers
The Fabius C compiler cannot compile a .c file that begins with a number. There are no other restrictions, numbers are allowed as long as they aren't the first character. If a file does begin with a number you are likely to get a string of error messages, like this:
WARNING: Duplicated symbol "_forth?ArrayFetch" (in
'C:\Mosaic\Fabius\Lib\qeddrvrs.o11' &
'C:\Mosaic\Fabius\Lib\qeddrvrs.o11') !
WARNING: Duplicated symbol "_forth?FArrayFetch" (in
'C:\Mosaic\Fabius\Lib\qeddrvrs.o11' &
'C:\Mosaic\Fabius\Lib\qeddrvrs.o11') !
WARNING: Duplicated symbol "_forth?ArrayStore" (in
'C:\Mosaic\Fabius\Lib\qeddrvrs.o11' &
'C:\Mosaic\Fabius\Lib\qeddrvrs.o11') !
...
... PORTA and ChangeBits
This note applies to the use of PORTA, PORTB, PORTC, PORTD, PORTE, PORTF, PORTG in conjunction with ChangeBits(), ClearBits(), SetBits(), ToggleBits(). If a port passed into one of these functions as the address paramater, it is logically correct to use an ampersand ( & ). This however causes a compiler error. The solution is C's built in bitwise operators to achieve the desired effect.
See this section for more information: create-your-own-uninterruptable-functions.
