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.

C/C++ > compiler warnings

#168951 - moonlightcheese - Fri Jun 05, 2009 1:48 am

getting warnings with this code:

Code:
   if(bgmode) {
      if(addr>=0x06010000 && addr<=0x06017FE0) {      //check for valid VRAM address range
         return (((unsigned int)addr)>>5)&0x03FF;
      }
   } else {
      if(addr>=0x06014000 && addr<=0x06017FE0) { 
         return (((unsigned int)addr)>>5)&0x03FF;   //tile indices are the same in both modes
      }
   }

about comparing pointers to integers. is there a better way to write this code so i don't get these warnings?

#168952 - Dwedit - Fri Jun 05, 2009 1:50 am

Add (u32*) before each 0x in the addresses, or whatever type your pointer is.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#168965 - Ruben - Sat Jun 06, 2009 12:00 pm

Or you could do this, too...

Code:
   if(bgmode) {
      if(&addr>=0x06010000 && &addr<=0x06017FE0) {      //check for valid VRAM address range
         return (((unsigned int)addr)>>5)&0x03FF;
      }
   } else {
      if(&addr>=0x06014000 && &addr<=0x06017FE0) { 
         return (((unsigned int)addr)>>5)&0x03FF;   //tile indices are the same in both modes
      }
   }

Also note that, if you're using a late/new enough compiler, you can use /32 instead of >>5; it will handle it automatically.

#168966 - Dwedit - Sat Jun 06, 2009 12:59 pm

I don't think that works, you're requesting the address of a pointer variable here.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#168968 - Ruben - Sat Jun 06, 2009 2:36 pm

Whoops, yeah, replace the & with (u32) and that should work.