ARM Technical Support Knowledge Articles

ERROR C249 (SPECIAL INITIALIZATION EXCEEDS 8K)

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

I'm using the C51 compiler. When I define an array allocating more than 8K in XDATA, I get the following error:

*** ERROR C249 IN LINE 14 OF MAIN.C: 'xbuf': SPECIAL INITIALIZATION EXCEEDS 8K

My code is written as follows:

unsigned char xdata xbuf [9600] =
  {
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
.
.
.
  };

How do I solve this problem?

ANSWER

When you create an initialized array in xdata, your program must actually store the data in CODE space and copy it to the XDATA array at initialization time. This is done by the code in INIT.A51. Problems occur when the size of an initialized object exceeds 8K and the compiler the lists the error you received.

There are several solutions to this problem.

  1. If the array does not need to be in XDATA space, change the declaration to CODE. Then, you will not receive the error.
  2. If the array must be in XDATA space, then create an uninitialized array in XDATA. Create an initialized array in CODE containing the data. Use the memcpy library routine to copy the data from the CODE array to the XDATA array. This uses no more memory than initializing the XDATA array but you must explicitly copy the data into the XDATA array (using memcpy). For example:
    unsigned char xdata xbuf [9600];
    unsigned char code cbuf [] =
      {
      // Initialized data goes here
      };
    
    void main (void)
    {
    memcpy (xbuf, cbuf, min (sizeof (xbuf), sizeof (cbuf)));
    .
    .
    .
    }
    

Article last edited on: 2005-07-09 09:59:30

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential