digitalmars.D.bugs - games with toString()
- Kris (14/14) Dec 10 2005 toString(int) returns a shared, global slice for small numbers:
- JT (6/20) Dec 11 2005 WOOOOOOW! ok yeah Ive had weird problems like this and Im learning more ...
- Sean Kelly (4/23) Dec 11 2005 I suspect this is a const string and attempting the above on Linux would...
- Kris (2/6) Dec 11 2005 You just gave me an idea ;-)
toString(int) returns a shared, global slice for small numbers: import std.string; import std.stdio; void main() { char[] c = toString(1); writefln (c); c[0] = '!'; writefln (toString(1)); } emits: 1 ! Read-only arrays would resolve this, and a whole lot more besides :-)
Dec 10 2005
In article <dng17i$6n6$1 digitaldaemon.com>, Kris says...toString(int) returns a shared, global slice for small numbers: import std.string; import std.stdio; void main() { char[] c = toString(1); writefln (c); c[0] = '!'; writefln (toString(1)); } emits: 1 ! Read-only arrays would resolve this, and a whole lot more besides :-)WOOOOOOW! ok yeah Ive had weird problems like this and Im learning more every day about how D handles these things. Thanks very much for pointing this out - ive got .dups sprinkled all over my code becuase Im still trying to figure out what these problems are - but you just gave me some important information. Its quite straightforward but D is certainly a new paradigm one has to get used to.
Dec 11 2005
Kris wrote:toString(int) returns a shared, global slice for small numbers: import std.string; import std.stdio; void main() { char[] c = toString(1); writefln (c); c[0] = '!'; writefln (toString(1)); } emits: 1 ! Read-only arrays would resolve this, and a whole lot more besides :-)I suspect this is a const string and attempting the above on Linux would result in a run-time error. But it's a good point nevertheless :-) Sean
Dec 11 2005
"Sean Kelly" <sean f4.ca> wroteKris wrote:You just gave me an idea ;-)Read-only arrays would resolve this, and a whole lot more besides :-)I suspect this is a const string and attempting the above on Linux would result in a run-time error. But it's a good point nevertheless :-)
Dec 11 2005