Size code grows very quickly when a six elements char array is declared.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Size code grows very quickly when a six elements char array is declared.

646 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Sat May 02 18:42:21 MST 2015
Hi

I faced this problem: The code I'm working on is 5064 bytes in text, and 12 bytes in data. However, when I declare a simple char array the text size grows to 17128, and data grows to 2132.

The text/data size is 5064/12 with the newer code commented :

const uint8_t ROWS_PER_CHAR = 7;
// ...

//static const uint8_t z[ROWS_PER_CHAR] = {6, 0, 1, 2, 3, 4, 5};

void Print(Dots_Type * screen)
{
static uint8_t i = 0;
//static uint8_t j = z;

// ...

//j = z;
}


Now, commenting out the code that creates and uses the array, the text/data size is 17128/2132:

const uint8_t ROWS_PER_CHAR = 7;
// ...

static const uint8_t z[ROWS_PER_CHAR] = {6, 0, 1, 2, 3, 4, 5};

void Print(Dots_Type * screen)
{
static uint8_t i = 0;
static uint8_t j = z;

// ...

j = z;
}


BTW, it doesn't matter whether the char array declaration is made inside the Print() function or global (as shown).

This is a C++ project, with C native code, like the SysTick handler, which in turn is calling the Print() function:

#ifdef __cplusplus
extern "C"
{
#endif

void SysTick_Handler(void)
{
  // ...
  
  Print(&screen);

}

#ifdef __cplusplus
}
#endif


Any ideas what is this happening? I can change the code inside Print() so not to use the array, but that would be an ugly workaround.

Thank you!
Labels (1)
0 Kudos
2 Replies

614 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Sat May 02 20:45:16 MST 2015
Hi R2D2

Your code works!

In fact, the variable 'j' needn't to be static at all 'cause its' not holding any state as 'i' is doing.

Although your workaround works, whenever I have some free time I'll try to find out why the code size grows insanely that big.

Thank you!
0 Kudos

614 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat May 02 19:53:32 MST 2015
Did you try:

static uint8_t i = 0;
[color=#f00]static uint8_t j;[/color]
j= z;

// ...

j = z;

0 Kudos