# IAR errors about extern and global vriables

I want to get values of a global array in a c file. the print screen of code is shown below:

'data' is the global array and 'slave_buffer_rx' is another global array defined in this file to get values of 'data'.each red cross has two errors:

1. Error[Pe094]: the size of an array must be greater than zero
2. Error[Pe028]: expression must have a constant value

I know how to get rid of errors: make assignments in a local function. the code without errors is shown below:

But I do not known the exact reasons and how can IAR consider it as an array with zero length. Can anyone give me some ideas?

• Why are yo using screendumps instead of pasting text? With your method nobody can search your question for matching text. – jippie May 12 '13 at 9:09

There are a few problems, take the first line for example:

__IO uint8_t Slave_Buffer_Rx[0]=data[0];


This is trying to declare a zero length array and also assign a non-constant value to it. The first [0] is specifying the length of the array as zero. What you're attempting above is a static inialization so using data[0] doesn't make much sense at that point because during program initialization the pointer value won't be known.

Because you're using pointers and the values will be one and the same I don't see an immediate reason to use any different variables. If your ISR routine needs to write data to your global buffer you could use something like the following for example:

INTERRUPT_HANDLER(I2C_IRQHandler, 19)
{