How do I find the length of strings within an array at compile time?
The following is not safe:
const char* MyStrings[] =
{
"one",
"two",
"three",
"end marker"
}
#define StringLength(index) MyStrings[index+1] - MyStrings[index]
Since the strings may not be placed consecutively, or in order, within
memory.
Also
#define String1 "one"
#define String2 "two"
#define String3 "three"
const char* MyStrings[] =
{
String1,
String2,
String3
}
int StringLengths[] =
{
size(String1),
size(String2),
size(String3)
}
is a bit too cumbersome.
Any better suggestions?
Cheers,
Paul.
--
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
-- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line. Sorry.


|