More Flexible Handling Of Constant Data

There are a few ways of allowing pointers to constant data. First, pointers to constants:

 

/*
A simple example showing the assignment of a pointer to a constant with the address of a constant string:
*/

ROM char version[] = "PRODUCT ID V1.01";
ROM char *ptr;

ptr = &version[0];

 

/*
A more complex example that creates an array of pointers to constant strings:
*/

ROM char *strings[] =
{
   "HELLO",
   "WORLD",
   "CONST",
   "STRINGS"
};

/*
Access the above const pointers
*/

ROM char *ptr;
while (i = 0; i < (sizeof(strings) / sizeof(const char *)); i++)
{
   ptr = strings[i];
   printf("%s", ptr);
}

 

In addition, constant strings can be passed to functions that are normally looking for pointers to characters:

 

/*
The following enables the ability for the compiler to copy constant strings into RAM when being passed as a parameter to a function:
*/

#device PASS_STRINGS=IN_RAM

/*
An example of using this new feature:
*/

if (stricmp(buffer,"ATDT\r")==0)
{
   //do something
}

 

Note: The const qualifier in CCS always means that the data will be placed in program memory, and that the data is 'read-only'. It does not follow the ANSI definition which simply states that const is 'read-only'.