D.gnu - Is this right?
- Regan Heath (31/31) Jun 08 2004 Hi,
- Regan Heath (6/36) Jun 08 2004 Whoops, I posted this is so totally the wrong group. My appologies. And
- Arcane Jill (3/6) Jun 08 2004 Arcane Jill
- Regan Heath (6/11) Jun 08 2004 It doesn't work "non-constant expression a[0..3]".
- Arcane Jill (6/12) Jun 08 2004 Whoops. I meant:
- Regan Heath (7/20) Jun 08 2004 Same error. Are you trying these? I have tried a number of things, just
- Arcane Jill (4/15) Jun 08 2004 It compiles for me. I'm using the latest compiler, too.
- Regan Heath (13/29) Jun 08 2004 My appologies, I need the static array to me at module level, my code
- Ilya Minkov (10/57) Jun 09 2004 I think you should report it to D.bugs. Intuitive things should work
- Regan Heath (8/66) Jun 09 2004 That is my problem.. I am actually trying to define an array whose
- Ilya Minkov (6/17) Jun 10 2004 Already tried the const storage modifier on the original array?
- Regan Heath (11/27) Jun 10 2004 It does not. I believe this..
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/
Jun 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/
Jun 08 2004
In article <opr9arqga75a2sq9 digitalmars.com>, Regan Heath says... Do this:Arcane Jillstatic char[6] a = "abcdef"; static char[] p = a[0..3]; static char[] q = a[3..6];
Jun 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:It doesn't work "non-constant expression a[0..3]". Regan. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/static char[6] a = "abcdef"; static char[] p = a[0..3]; static char[] q = a[3..6];
Jun 08 2004
In article <opr9auakwt5a2sq9 digitalmars.com>, Regan Heath says...Whoops. I meant: static char[6] a = "abcdef"; char[] p = a[0..3]; char[] q = a[3..6]; JillDo this:It doesn't work "non-constant expression a[0..3]".static char[6] a = "abcdef"; static char[] p = a[0..3]; static char[] q = a[3..6];
Jun 08 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...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/Whoops. I meant: static char[6] a = "abcdef"; char[] p = a[0..3]; char[] q = a[3..6];Do this:It doesn't work "non-constant expression a[0..3]".static char[6] a = "abcdef"; static char[] p = a[0..3]; static char[] q = a[3..6];
Jun 08 2004
In article <opr9avyz0d5a2sq9 digitalmars.com>, Regan Heath says...Hey, that one worked for me! Look, see - here's my source code:static char[6] a = "abcdef"; char[] p = a[0..3]; char[] q = a[3..6];Same error. Are you trying these?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
Jun 08 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...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/Hey, that one worked for me! Look, see - here's my source code:static char[6] a = "abcdef"; char[] p = a[0..3]; char[] q = a[3..6];Same error. Are you trying these?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.
Jun 08 2004
Regan Heath schrieb: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:I think you should report it to D.bugs. Intuitive things should work unless there is a strong argument somewhere against.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];It is definately not copying, it's only taking a slice into a static storage. You can use .dup on a slice to make a real copy. BTW, why do you use static at a module level? It doesn't work the same as in C. I think it simply gets ignored at the module level. In D you use keyword "private" for that. Refer to doc section on attributes for details. -eyebut, 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...
Jun 09 2004
On Wed, 09 Jun 2004 11:04:51 +0200, Ilya Minkov <minkov cs.tum.edu> wrote:Regan Heath schrieb:I will.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:I think you should report it to D.bugs. Intuitive things should work unless there is a strong argument somewhere against.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];That is my problem.. I am actually trying to define an array whose contents cannot be modified.It is definately not copying, it's only taking a slice into a static storage. You can use .dup on a slice to make a real copy. BTW, why do you use static at a module level? It doesn't work the same as in C.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...I think it simply gets ignored at the module level. In D you use keyword "private" for that. Refer to doc section on attributes for details.Thanks, but I'm not trying to 'hide' the array, just make it const. Regan-eye-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jun 09 2004
Regan Heath schrieb:BTW, why do you use static at a module level? It doesn't work the same as in C.That is my problem.. I am actually trying to define an array whose contents cannot be modified.Already tried the const storage modifier on the original array? According to my understanding of specification, it should place it into constant storage, and the application should segfault or assert whenever trying to write into it. -eyeI think it simply gets ignored at the module level. In D you use keyword "private" for that. Refer to doc section on attributes for details.Thanks, but I'm not trying to 'hide' the array, just make it const.
Jun 10 2004
On Thu, 10 Jun 2004 20:51:09 +0200, Ilya Minkov <minkov cs.tum.edu> wrote:Regan Heath schrieb:Yes.BTW, why do you use static at a module level? It doesn't work the same as in C.That is my problem.. I am actually trying to define an array whose contents cannot be modified.Already tried the const storage modifier on the original array?I think it simply gets ignored at the module level. In D you use keyword "private" for that. Refer to doc section on attributes for details.Thanks, but I'm not trying to 'hide' the array, just make it const.According to my understanding of specification, it should place it into constant storage, and the application should segfault or assert whenever trying to write into it.It does not. I believe this.. const int[3] aa = [ 1,2,3 ]; defines a constant array reference to non constant data. Meaning you can modify the data, but you cannot go.. int[] bb = [ 1,2,3,4,5 ]; aa = bb; Regan. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jun 10 2004