digitalmars.D.learn - How to initialise array of ubytes?
- Paul (7/7) Nov 29 2014 I'm trying to do this:
- bearophile (13/18) Nov 29 2014 This works:
- Paul (5/15) Nov 29 2014 I'm afraid I don't know. I would guess it's something to do with
- Xinok (10/32) Nov 30 2014 More generally, it's because one is static (as in global /
- Daniel Kozak via Digitalmars-d-learn (5/12) Nov 29 2014 http://stackoverflow.com/questions/24600796/d-set-default-value-for-a-st...
- bearophile (5/6) Nov 29 2014 Do you also know why the simplest syntax doesn't work? Can't it
- Daniel Kozak (11/17) Nov 29 2014 I don't know. But this works too:
- bearophile (5/6) Nov 30 2014 I have added an ER:
- Paul (2/8) Nov 30 2014 Glad to hear it's not just me being dense for a change :D
- ketmar via Digitalmars-d-learn (7/23) Nov 29 2014 On Sat, 29 Nov 2014 21:28:36 +0100
I'm trying to do this: ubyte[MAPSIZE][MAPSIZE] map = 1; but it doesn't work and I can't seem to cast the value to a ubyte (which looks rather ugly and out of place in D anyway). Is there a way to do this other than using a couple of loops? Cheers Paul
Nov 29 2014
Paul:I'm trying to do this: ubyte[MAPSIZE][MAPSIZE] map = 1; but it doesn't work and I can't seem to cast the value to a ubyte (which looks rather ugly and out of place in D anyway). Is there a way to do this other than using a couple of loops?This works: enum MAPSIZE = 3; void main() { ubyte[MAPSIZE][MAPSIZE] map2 = 1; } This doesn't work: enum MAPSIZE = 3; ubyte[MAPSIZE][MAPSIZE] map1 = ubyte(1); void main() {} Why isn't this working? Bye, bearophile
Nov 29 2014
On Saturday, 29 November 2014 at 20:22:40 UTC, bearophile wrote:This works: enum MAPSIZE = 3; void main() { ubyte[MAPSIZE][MAPSIZE] map2 = 1; } This doesn't work: enum MAPSIZE = 3; ubyte[MAPSIZE][MAPSIZE] map1 = ubyte(1); void main() {} Why isn't this working?I'm afraid I don't know. I would guess it's something to do with trying to initialise the array in the global scope but you've also changed the expression in the non-working example. I don't have access to my machine at present so I can't experiment!
Nov 29 2014
On Saturday, 29 November 2014 at 20:47:09 UTC, Paul wrote:On Saturday, 29 November 2014 at 20:22:40 UTC, bearophile wrote:More generally, it's because one is static (as in global / thread-local) and the other is not. Take the working example, put "static" in front of the declaration, and you'll get the same error. There are different rules regarding the initialization of static and non-static variables. My guess, they're implemented as separate features in the compiler, so when vector operations were introduced, nobody thought to implement this feature as a way to initialize static arrays as well.This works: enum MAPSIZE = 3; void main() { ubyte[MAPSIZE][MAPSIZE] map2 = 1; } This doesn't work: enum MAPSIZE = 3; ubyte[MAPSIZE][MAPSIZE] map1 = ubyte(1); void main() {} Why isn't this working?I'm afraid I don't know. I would guess it's something to do with trying to initialise the array in the global scope but you've also changed the expression in the non-working example. I don't have access to my machine at present so I can't experiment!
Nov 30 2014
Dne Sat, 29 Nov 2014 21:10:41 +0100 Paul via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> napsal(a):I'm trying to do this: ubyte[MAPSIZE][MAPSIZE] map = 1; but it doesn't work and I can't seem to cast the value to a ubyte (which looks rather ugly and out of place in D anyway). Is there a way to do this other than using a couple of loops? Cheers Paul-- Vytvořeno poštovní aplikací Opery: http://www.opera.com/mail/
Nov 29 2014
Daniel Kozak:Do you also know why the simplest syntax doesn't work? Can't it be implemented and added to the D language? Bye, bearophile
Nov 29 2014
On Saturday, 29 November 2014 at 20:45:34 UTC, bearophile wrote:Daniel Kozak:I don't know. But this works too: module main; import std.stdio; int[5][5] p; static this() { p = 1; } void main() { writeln(p); }Do you also know why the simplest syntax doesn't work? Can't it be implemented and added to the D language? Bye, bearophile
Nov 29 2014
Daniel Kozak:I don't know. But this works too:I have added an ER: https://issues.dlang.org/show_bug.cgi?id=13799 Bye, bearophile
Nov 30 2014
On Sunday, 30 November 2014 at 11:13:56 UTC, bearophile wrote:Daniel Kozak:Glad to hear it's not just me being dense for a change :DI don't know. But this works too:I have added an ER: https://issues.dlang.org/show_bug.cgi?id=13799 Bye, bearophile
Nov 30 2014
On Sat, 29 Nov 2014 21:28:36 +0100 Daniel Kozak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:Dne Sat, 29 Nov 2014 21:10:41 +0100 Paul via Digitalmars-d-learn =20 <digitalmars-d-learn puremagic.com> napsal(a): =20h =20I'm trying to do this: ubyte[MAPSIZE][MAPSIZE] map =3D 1; but it doesn't work and I can't seem to cast the value to a ubyte (whic==20looks rather ugly and out of place in D anyway). Is there a way to do =aaaargh, make me unsee that! that's... disgusting.this other than using a couple of loops? Cheers Paul=20 http://stackoverflow.com/questions/24600796/d-set-default-value-for-a-str=
Nov 29 2014