Length of Strings in an Array at compile-time
  Home FAQ Contact Sign in
alt.comp.lang.c only
 
Advanced search
POPULAR GROUPS

more...

alt.comp.lang.c Profile…
 Up
Length of Strings in an Array at compile-time         


Date: Apr 29, 2008 05:41

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"
Show full article (0.65Kb)
5 Comments
Re: Length of Strings in an Array at compile-time         


Author: mimus
Date: Apr 29, 2008 14:06

On Tue, 29 Apr 2008 13:41:51 +0100, Paul wrote:
> 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.
Show full article (1.38Kb)
no comments
Re: Length of Strings in an Array at compile-time         


Author: Barry Schwarz
Date: Apr 29, 2008 18:34

On Tue, 29 Apr 2008 17:06:49 -0400, mimus hotmail.com>
wrote:
>On Tue, 29 Apr 2008 13:41:51 +0100, Paul wrote:
>
>> How do I find the length of strings within an array at compile time?
>>
>> The following is not safe:
>>
>> const char* MyStrings[] =
>> {
>> ...
Show full article (1.43Kb)
no comments
Re: Length of Strings in an Array at compile-time         


Author: Barry Schwarz
Date: Apr 29, 2008 18:34

On Tue, 29 Apr 2008 13:41:51 +0100, "Paul" <-> wrote:
Show full article (1.05Kb)
no comments
Re: Length of Strings in an Array at compile-time         


Author: mimus
Date: Apr 29, 2008 23:43

On Tue, 29 Apr 2008 18:34:16 -0700, Barry Schwarz wrote:
> On Tue, 29 Apr 2008 17:06:49 -0400, mimus hotmail.com>
> wrote:
>
>>On Tue, 29 Apr 2008 13:41:51 +0100, Paul wrote:
>>
>>> How do I find the length of strings within an array at compile...
Show full article (2.96Kb)
no comments
Re: Length of Strings in an Array at compile-time         


Author: Donkey Hot
Date: Apr 30, 2008 09:04

mimus hotmail.com> wrote in
news:gcKdnaia7-tqiYXVnZ2dnUVZ_rSrnZ2d@giganews.com:
Show full article (0.95Kb)
no comments