Variable Length Constant Strings

Examine this example of an ineffecient array of constant strings:


const char strings[3][15] =
{
   "HELLO",
   "WORLD",
   "EXTRALONGERWORD"
};

In the above example we had to make the maximum length of each string be 15 characters because of the length of "EXTRALONGERWORD". But since "HELLO" and "WORLD" are only 6 characters (don't forget null termination), 9 bytes are wasted for each.


To alleviate this problem, use this method for variable length constant strings:


const char strings[][*] =
{
   "HELLO",
   "WORLD",
   "EXTRALONGERWORD"
};

Note: this is done by adding extra intelligence to the indexing of the constant data table. Because of this you cannot create a pointer to a variable length constant string.


C-Aware IDE Demo
Embedded C Learners Kit
EZ App Lynx