[A89] Variables in C


[Prev][Next][Index][Thread]

[A89] Variables in C



Hello,

I was wondering, is it faster (more efficient) to declare global variables
*once* outside a function, rather than redeclare them every time the
function is run? For example, which would be better to do between the two
following codes below if they were used very often...

void ShowFrogSprite(int x, int y) { // 60 bytes larger than the below
example
  unsigned short frog_black[] = {0b0000011111100000, // Use this sprite to
turn all of the black pixils on
                  0b0000100000010000,0b0001000000001000,0b0001000000001000,
                  0b0011000000001100,0b0111000000001110,0b0100100000010010,
                  0b0100010000100010,0b1110000000000111,0b1001000000001001,
                  0b1000011111100001,0b0111100000011110};
  unsigned short frog_white[] = {0b1111100000011111, // Use this sprite to
turn all of the white pixils INSIDE frogger off
                   0b1111000000001111,0b1111000000001111,0b1111000000001111,
                   0b1100000000000011,0b1111000000001111,0b1100100000010011,

0b1100010000100011,0b1110000000000111,0b1111000000001111};
  Sprite16(x,y,13,frog_black,LCD_MEM,SPRT_OR);
  Sprite16(x,y+1,10,frog_white,LCD_MEM,SPRT_AND);
}

////////////////////////////////////////////////
//-------------OR------------//
///////////////////////////////////////////////
// 60 bytes smaller than the above example
  unsigned short frog_black[] = {0b0000011111100000, // Use this sprite to
turn all of the black pixils on
                  0b0000100000010000,0b0001000000001000,0b0001000000001000,
                  0b0011000000001100,0b0111000000001110,0b0100100000010010,
                  0b0100010000100010,0b1110000000000111,0b1001000000001001,
                  0b1000011111100001,0b0111100000011110};
  unsigned short frog_white[] = {0b1111100000011111, // Use this sprite to
turn all of the white pixils INSIDE frogger off
                   0b1111000000001111,0b1111000000001111,0b1111000000001111,
                   0b1100000000000011,0b1111000000001111,0b1100100000010011,

0b1100010000100011,0b1110000000000111,0b1111000000001111};
void ShowFrogSprite(int x, int y) {
  Sprite16(x,y,13,frog_black,LCD_MEM,SPRT_OR);
  Sprite16(x,y+1,10,frog_white,LCD_MEM,SPRT_AND);
}


~Angelboy