gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Devkit pro wont accept my for loop

#176806 - blessingta@hotmail.co.uk - Fri Oct 14, 2011 5:22 pm

hi

I'm trying to create a for loop in order to create some programmer font art but it wont work. because devkit pro has some "C99" mode issue. Bellow is my programmer art fonts (in the for loop) and after that is the error.

Code:
   //Where our characters are located
    unsigned int *CharPtr = CHAR_BASE_ADR(0);
   
    int Random_Colour = 0;
    int Random_Colour2 = 0;
   
   void btafonts_init()
   {
   //90 is the amount of ascii characters I'm creating
   for ( int i = 0; i < 90; i++)
   {
   
   //Create Place holders for my characters (programmer art)
   //the combination of 4 abitary colours are used to differentiate what will be differnt fonts.
   //these fonts will be a random combination of four, of the 16 colours in any pallete 
   
   //Random colour chooses any 1 of the 16 colours
   //(this if statement stops it from writing a number greater than 15)
   if ((Random_Colour = i % 16) > 12) Random_Colour -= 12;//thus cycling back to 0
   
   Random_Colour2 = i % 10;// other random colours being added
   CharPtr[(65*8+0)] = ((Random_Colour<<28)|(Random_Colour<<24)|(Random_Colour<<20)| (Random_Colour<<06) | (Random_Colour<<02) | (Random_Colour<<8) | (Random_Colour<<4)| (Random_Colour<<0));
   CharPtr[(65*8+1)] = ((Random_Colour<<28)|(Random_Colour<<24)|(Random_Colour<<20)| (Random_Colour<<06) | (Random_Colour<<02) | (Random_Colour<<8) | (Random_Colour<<4)| (Random_Colour<<0));
   CharPtr[(65*8+2)] = (((Random_Colour+1)<<28)|((Random_Colour+1)<<24)|((Random_Colour+1)<<20)| ((Random_Colour+1)<<06) | ((Random_Colour+1)<<02) | ((Random_Colour+1)<<8) | ((Random_Colour+1)<<4)| ((Random_Colour+1)<<0));
   CharPtr[(65*8+3)] = (((Random_Colour+1)<<28)|((Random_Colour+1)<<24)|((Random_Colour+1)<<20)| ((Random_Colour+1)<<06) | ((Random_Colour+1)<<02) | ((Random_Colour+1)<<8) | ((Random_Colour+1)<<4)| ((Random_Colour+1)<<0));
   CharPtr[(65*8+4)] = (((Random_Colour+2)<<28)|((Random_Colour+2)<<24)|((Random_Colour+2)<<20)| ((Random_Colour+2)<<06) | ((Random_Colour+2)<<02) | ((Random_Colour+2)<<8) | ((Random_Colour+2)<<4)| ((Random_Colour+2)<<0));


Whats the meaning of this error?

Quote:
> "make"
main.c
arm-eabi-gcc -MMD -MP -MF /c/users/portsmouthuni/my_gba/build/main.d -g -Wall -O3 -mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer -ffast-math -mthumb -mthumb-interwork -I/c/users/portsmouthuni/my_gba/include -I/c/devkitPro/libgba/include -I/c/users/portsmouthuni/my_gba/build -c /c/users/portsmouthuni/my_gba/source/main.c -o main.o
In file included from c:/users/portsmouthuni/my_gba/source/main.c:10:0:
c:/users/portsmouthuni/my_gba/include/btafonts.h: In function 'btafonts_init':
c:/users/portsmouthuni/my_gba/include/btafonts.h:33:2: error: 'for' loop initial declarations are only allowed in C99 mode
c:/users/portsmouthuni/my_gba/include/btafonts.h:33:2: note: use option -std=c99 or -std=gnu99 to compile your code
c:/users/portsmouthuni/my_gba/source/main.c: In function 'main':
c:/users/portsmouthuni/my_gba/source/main.c:82:2: error: 'for' loop initial declarations are only allowed in C99 mode
make[1]: *** [main.o] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
> Time Taken: 00:01
[/code]

#176807 - Dwedit - Fri Oct 14, 2011 5:26 pm

I guess you can add "-std=c99" to your CFLAGS in the makefile.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#176824 - vuurrobin - Fri Oct 14, 2011 9:21 pm

putting variable declaration in for loops, like "for ( int i = ", isn't allowed in c89 (which is the default, I think)

to fix it, do as Dwedit says and use c99.

and DevkitPro is a toolchain vendor. you are talking about either DevkitARM, DevkitPPC or DevkitPSP.
_________________
my blog:
http://vuurrobin.100webcustomers.com/

#176906 - sverx - Mon Oct 17, 2011 9:02 am

this will work:

Code:
int i;
for (i = 0; i < 90; i++)

#176925 - Cearn - Sun Oct 23, 2011 9:05 pm

I know this isn't directly related to your original question, but ...

blessingta@hotmail.co.uk wrote:
Code:

...
   CharPtr[(65*8+0)] = ((Random_Colour<<28)|(Random_Colour<<24)|(Random_Colour<<20)| (Random_Colour<<06) | (Random_Colour<<02) | (Random_Colour<<8) | (Random_Colour<<4)| (Random_Colour<<0));
...
  1. Don't you mean "... (Random_Colour<<16) | (Random_Colour<<12) ..." here?
  2. If so, you can get the same result (assuming Random_Colour is between 0 and 16) using "Random_Colour*0x11111111". Easier to write and easier to read.

#176927 - kusma - Mon Oct 24, 2011 11:31 am

Cearn wrote:
I know this isn't directly related to your original question, but ...

blessingta@hotmail.co.uk wrote:
Code:

...
   CharPtr[(65*8+0)] = ((Random_Colour<<28)|(Random_Colour<<24)|(Random_Colour<<20)| (Random_Colour<<06) | (Random_Colour<<02) | (Random_Colour<<8) | (Random_Colour<<4)| (Random_Colour<<0));
...
  1. Don't you mean "... (Random_Colour<<16) | (Random_Colour<<12) ..." here?

It's also worth noting that numbers prefixed with a zero are octal numbers (as opposed to decimal numbers). It's not a bug in this case as the numbers are below 8, but it's something to be aware of. In general, I'd say writing numbers that aren't "naturally octal" in octal form is bad practice.

#176929 - sverx - Tue Oct 25, 2011 9:47 am

I really didn't know that! 8| 8| Thanks! Now I just hope I never wrote any leading zero to my decimals...
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary

#176930 - blessingta@hotmail.co.uk - Wed Oct 26, 2011 4:34 pm

its ok the problem has been fixed;

thanks for the "int outside for loop advice"