Keil Logo

C51: STRING TABLE IN XDATA

QUESTION

How do I locate an initialized array in XDATA memory. I am declaring an array thus:

char * lcd_message = { "message 1", "message 2", ... "last message" };

and need to get the messages and pointers into XDATA as they may be changed during runtime.

ANSWER

The best way to do this is to declare the messages separately from the array. For example:

#include <stdio.h>

char xdata m1 [] = "Message One";
char xdata m2 [] = "Message Two";
char xdata m3 [] = "Message Three";

xdata char xdata *message_table [] =
  {
  m1,
  m2,
  m3,
  NULL,
  };

char xdata NULL_PLACE_HOLDER _at_ 0;

This is the only way to force the constant strings into XDATA instead of CONSTANT (code) memory.

Note that the NULL_PLACE_HOLDER is declared to reside at 0 in XDATA. That is probably useful if you will test for NULL pointers.

Last Reviewed: Monday, June 26, 2000


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.