Jump to page: 1 2
Thread overview
Is this right?
Jun 08, 2004
Regan Heath
Jun 08, 2004
Regan Heath
Jun 08, 2004
Arcane Jill
Jun 08, 2004
Regan Heath
Jun 08, 2004
Arcane Jill
Jun 09, 2004
Regan Heath
Jun 09, 2004
Arcane Jill
Jun 09, 2004
Regan Heath
Jun 09, 2004
Regan Heath
Jun 09, 2004
Ivan Senji
Jun 09, 2004
Regan Heath
Jun 10, 2004
Ivan Senji
Jun 09, 2004
Arcane Jill
Jun 09, 2004
Regan Heath
Jun 09, 2004
Ilya Minkov
Jun 09, 2004
Regan Heath
Jun 10, 2004
Ilya Minkov
Jun 10, 2004
Regan Heath
June 08, 2004
Hi,

Ok basically I have a big static array, into which I want 4 static slices.

I thought this would work...

static char[6] a = "abcdef";
static char[3] p = a[0..3];
static char[3] q = a[3..6];

but, the slices are char[] and you cannot assign a char[] to a char[3] (even if they are the same length). So I tried...

static char[6] a = "abcdef";
static char[3] p = cast(char[3])a[0..3];
static char[3] q = cast(char[3])a[3..6];

and now it does not like it because cast(char[3])a[0..3] is a non constant expression.

So, is there any way to define a bunch of static slices into a static array?


I did get this to compile...

static char[6] a = "abcdef";
char[3] p;
char[3] q;

static this() {
	p[] = a[0..3];
	q[] = a[3..6];
}

int main(char[][] args) {
	return 0;
}

but, I am not 100% certain I know what it's doing exactly? is it copying? or just taking a static slice...

Regan.

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
June 08, 2004
Whoops, I posted this is so totally the wrong group. My appologies. And now I'm cross-posting.. can the kind people in digitalmars.D please read this. :)

On Wed, 09 Jun 2004 10:34:53 +1200, Regan Heath <regan@netwin.co.nz> wrote:

> Hi,
>
> Ok basically I have a big static array, into which I want 4 static slices.
>
> I thought this would work...
>
> static char[6] a = "abcdef";
> static char[3] p = a[0..3];
> static char[3] q = a[3..6];
>
> but, the slices are char[] and you cannot assign a char[] to a char[3] (even if they are the same length). So I tried...
>
> static char[6] a = "abcdef";
> static char[3] p = cast(char[3])a[0..3];
> static char[3] q = cast(char[3])a[3..6];
>
> and now it does not like it because cast(char[3])a[0..3] is a non constant expression.
>
> So, is there any way to define a bunch of static slices into a static array?
>
>
> I did get this to compile...
>
> static char[6] a = "abcdef";
> char[3] p;
> char[3] q;
>
> static this() {
> 	p[] = a[0..3];
> 	q[] = a[3..6];
> }
>
> int main(char[][] args) {
> 	return 0;
> }
>
> but, I am not 100% certain I know what it's doing exactly? is it copying? or just taking a static slice...
>
> Regan.
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
June 08, 2004
In article <opr9arqga75a2sq9@digitalmars.com>, Regan Heath says...

Do this:

>> static char[6] a = "abcdef";
>> static char[] p = a[0..3];
>> static char[] q = a[3..6];

Arcane Jill


June 08, 2004
On Tue, 8 Jun 2004 22:58:17 +0000 (UTC), Arcane Jill <Arcane_member@pathlink.com> wrote:
> In article <opr9arqga75a2sq9@digitalmars.com>, Regan Heath says...
>
> Do this:
>
>>> static char[6] a = "abcdef";
>>> static char[] p = a[0..3];
>>> static char[] q = a[3..6];

It doesn't work "non-constant expression a[0..3]".

Regan.

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
June 08, 2004
In article <opr9auakwt5a2sq9@digitalmars.com>, Regan Heath says...
>
>> Do this:
>>
>>>> static char[6] a = "abcdef";
>>>> static char[] p = a[0..3];
>>>> static char[] q = a[3..6];
>
>It doesn't work "non-constant expression a[0..3]".

Whoops. I meant:

static char[6] a = "abcdef";
char[] p = a[0..3];
char[] q = a[3..6];

Jill


June 09, 2004
On Tue, 8 Jun 2004 23:57:31 +0000 (UTC), Arcane Jill <Arcane_member@pathlink.com> wrote:
> In article <opr9auakwt5a2sq9@digitalmars.com>, Regan Heath says...
>>
>>> Do this:
>>>
>>>>> static char[6] a = "abcdef";
>>>>> static char[] p = a[0..3];
>>>>> static char[] q = a[3..6];
>>
>> It doesn't work "non-constant expression a[0..3]".
>
> Whoops. I meant:
>
> static char[6] a = "abcdef";
> char[] p = a[0..3];
> char[] q = a[3..6];

Same error. Are you trying these? I have tried a number of things, just like these you are suggesting...

Regan

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
June 09, 2004
In article <opr9avyz0d5a2sq9@digitalmars.com>, Regan Heath says...
>
>> static char[6] a = "abcdef";
>> char[] p = a[0..3];
>> char[] q = a[3..6];
>
>Same error. Are you trying these?

Hey, that one worked for me! Look, see - here's my source code:

>   int main(char[][] args)
>   {
>       static char[6] a = "abcdef";
>       char[] p = a[0..3];
>       char[] q = a[3..6];
>       return 0;
>   }

It compiles for me. I'm using the latest compiler, too.

Jill


June 09, 2004
On Wed, 9 Jun 2004 00:22:10 +0000 (UTC), Arcane Jill <Arcane_member@pathlink.com> wrote:
> In article <opr9avyz0d5a2sq9@digitalmars.com>, Regan Heath says...
>>
>>> static char[6] a = "abcdef";
>>> char[] p = a[0..3];
>>> char[] q = a[3..6];
>>
>> Same error. Are you trying these?
>
> Hey, that one worked for me! Look, see - here's my source code:
>
>>   int main(char[][] args)
>>   {
>>       static char[6] a = "abcdef";
>>       char[] p = a[0..3];
>>       char[] q = a[3..6];
>>       return 0;
>>   }
>
> It compiles for me. I'm using the latest compiler, too.

My appologies, I need the static array to me at module level, my code reads:

static char[6] a = "abcdef";
char[] p = a[0..3];
char[] q = a[3..6];

int main(char[][] args) {
	return 0;
}

Regan

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
June 09, 2004
On Wed, 9 Jun 2004 00:22:10 +0000 (UTC), Arcane Jill <Arcane_member@pathlink.com> wrote:

> In article <opr9avyz0d5a2sq9@digitalmars.com>, Regan Heath says...
>>
>>> static char[6] a = "abcdef";
>>> char[] p = a[0..3];
>>> char[] q = a[3..6];
>>
>> Same error. Are you trying these?
>
> Hey, that one worked for me! Look, see - here's my source code:
>
>>   int main(char[][] args)
>>   {
>>       static char[6] a = "abcdef";
>>       char[] p = a[0..3];
>>       char[] q = a[3..6];
>>       return 0;
>>   }
>
> It compiles for me. I'm using the latest compiler, too.

My appologies, I need the static array to me at module level, my code reads:

static char[6] a = "abcdef";
char[] p = a[0..3];
char[] q = a[3..6];

int main(char[][] args) {
	return 0;
}

Regan

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
June 09, 2004
"Regan Heath" <regan@netwin.co.nz> wrote in message news:opr9a9juyw5a2sq9@digitalmars.com...
> On Wed, 9 Jun 2004 00:22:10 +0000 (UTC), Arcane Jill
> <Arcane_member@pathlink.com> wrote:
>
> > In article <opr9avyz0d5a2sq9@digitalmars.com>, Regan Heath says...
> >>
> >>> static char[6] a = "abcdef";
> >>> char[] p = a[0..3];
> >>> char[] q = a[3..6];
> >>
> >> Same error. Are you trying these?
> >
> > Hey, that one worked for me! Look, see - here's my source code:
> >
> >>   int main(char[][] args)
> >>   {
> >>       static char[6] a = "abcdef";
> >>       char[] p = a[0..3];
> >>       char[] q = a[3..6];
> >>       return 0;
> >>   }
> >
> > It compiles for me. I'm using the latest compiler, too.
>
> My appologies, I need the static array to me at module level, my code reads:

I don't know is this what you want but:

static char[6] a = "abcdef";
char[] p;
char[] q;

static this()
{
     p = a[0..3];
    q = a[3..6];
}

int main(char[][] args)
{
return 0;
}



> static char[6] a = "abcdef";
> char[] p = a[0..3];
> char[] q = a[3..6];
>
> int main(char[][] args) {
> return 0;
> }
>
> Regan
>
> --
> Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


« First   ‹ Prev
1 2