Topic : Can't use XRAM for storing array of strings

Forum : 8051

Original Post
Post Information Post
November 14, 2009 - 12:30am
Guest

The following code compiles and works OK:

unsigned char *array[10];

array[0]="MENU 1";
array[1]="MENU 2";

but when I try to store the array in XRAM the compiler gives an error C203 ("different mspace") for the following code:

xdata unsigned char *array[10];

array[0]="MENU 1";
array[1]="MENU 2";

Can someone please tell me what I'm doing wrong.

Regards,

Bert van den Berg

Replies
Post Information Post
+1
0
-1
November 16, 2009 - 2:06pm
Guest

Hi

I think when changing memory space it is needed to precise the cast.
You can refer to RC51 documentation (Implementation)
The code below should give no error:


xdata unsigned char *array[10];
        array[0]= (unsigned char xdata  *)("Menu 1");
        array[1]= (unsigned char xdata  *)("MENU 2");


Regards,
Matloub

+1
0
-1
February 12, 2010 - 5:01pm
Guest

xdata unsigned char *array[10];

array[0]="MENU 1";

In this case array is an array located in the default memory space (data for small memory model, xdata for large memory model,...) of pointers to uchar in xdata. A string is located in CODE space. Therefore, the pointed spaces do not match.

If you wish to relocated the array in xdata, you have to place the 'xdata' keyword on the right side of the star (same rule as the ANSI rules for const/volatile) :
unsigned char * xdata array[10];

In this case, array[0] is considered as a generic pointer (if the default 'generic' mode is active), pointing either to code/data/xdata/....