daryooosh daryooosh - 6 months ago 39
C Question

XC8 : Cannot define auto array

I defined a auto char array as following :

char buffer[100];

When i compile it,the compiler return following error :

error: (1250) could not find space (100 bytes) for variable _buffer

But when i change it to:

static char buffer[100];

The program is compiled successfully.

Note 1:

My target device is 16f1829.

Note 2 :

Compiler version is 1.30.

Answer Source

All PIC16's have RAM banks which are 80 bytes of usable RAM per bank. This is described in section 3.2.4 Common RAM in the datasheet.

The problem you are seeing is not related to the size of the stack but rather the size of each item which can be allocated on the stack.

On XC8 auto variables cannot individually be larger than one bank of ram, which means the largest auto variable possible will be 80 bytes.

This is described in detail in the XC8 Compilers Users Guide in section as follows :

Unlike with non-auto variables, it is not efficient to access auto variables within the compiled stack using the linear memory of enhanced mid-range devices. For all devices, including PIC18 and Enhanced mid-range PIC MCUs, each component of the compiled stack must fit entirely within one bank of data memory on the target device (however, you can have more than one component, each allocated to a different bank). This limits the size of objects within the stack to the maximum free space of the bank in which it is allocated. The more auto variables in the stack; the more restrictive the space is to large objects. Recall that SFRs on mid-range devices are usually present in each data bank, so the maximum amount of GPR available in each bank is typically less than the bank size for these devices.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download