digitalmars.D - Nice feature, but...
- Andrew Fedoniouk (10/10) Apr 06 2005 In D I can declare new POD type with default value
- Ben Hinkle (5/10) Apr 06 2005 I think this is a bug in AA's and dynamic arrays resized by setting thei...
- Andrew Fedoniouk (4/15) Apr 06 2005 Thanks, Ben. For a while we should be careful because
- Regan Heath (54/63) Apr 07 2005 It seems to suffer from the same thing as a dynamic array, that is, if y...
- Walter (3/4) Apr 15 2005 It's a bad thing. It should be initialized to the .init value.
In D I can declare new POD type with default value like typedef uint symbol_t = 0xFFFFFFFF; This is just perfect and almost works. But not here: symbol_t[char[]] symbols; symbol_t v = symbols["arg"]; In ideal world 'v' should have 0xFFFFFFFF value but it has 0 instead. Is this so by design? Andrew.
Apr 06 2005
typedef uint symbol_t = 0xFFFFFFFF; symbol_t[char[]] symbols; symbol_t v = symbols["arg"]; In ideal world 'v' should have 0xFFFFFFFF value but it has 0 instead. Is this so by design?I think this is a bug in AA's and dynamic arrays resized by setting their length property - the memory is filled with 0 instead of the default value. So floating point values are filled with 0 instead of NaN and strings are filled with 0 instead of 0xFF. If you allocate a dynamic array using "new" it will get the right default values.
Apr 06 2005
Thanks, Ben. For a while we should be careful because if it will be fixed it could change behavior of existing code. So it is better not to use default values for a while. Andrew.typedef uint symbol_t = 0xFFFFFFFF; symbol_t[char[]] symbols; symbol_t v = symbols["arg"]; In ideal world 'v' should have 0xFFFFFFFF value but it has 0 instead. Is this so by design?I think this is a bug in AA's and dynamic arrays resized by setting their length property - the memory is filled with 0 instead of the default value. So floating point values are filled with 0 instead of NaN and strings are filled with 0 instead of 0xFF. If you allocate a dynamic array using "new" it will get the right default values.
Apr 06 2005
On Wed, 6 Apr 2005 16:16:58 -0700, Andrew Fedoniouk <news terrainformatica.com> wrote:In D I can declare new POD type with default value like typedef uint symbol_t = 0xFFFFFFFF; This is just perfect and almost works. But not here: symbol_t[char[]] symbols; symbol_t v = symbols["arg"]; In ideal world 'v' should have 0xFFFFFFFF value but it has 0 instead. Is this so by design?It seems to suffer from the same thing as a dynamic array, that is, if you create the type in-advertantly or indirectly it is initialised to 0, not it's init value. eg: import std.stdio; typedef uint symbol_t = 0xffffffff; void main() { writefln("[symbol_t]"); { symbol_t[char[]] symbols; symbol_t v = symbols["arg"]; symbol_t[1] test; symbol_t[] test2; symbol_t test3; test2.length = 1; writefln("%x",v); writefln("%x",test[0]); writefln("%x",test2[0]); writefln("%x",test3); } writefln(""); writefln("[CHAR]"); { char[char[]] symbols; char v = symbols["arg"]; char[1] test; char[] test2; char test3; test2.length = 1; writefln("%x",v); writefln("%x",test[0]); writefln("%x",test2[0]); writefln("%x",test3); } } Output: [symbol_t] 0 ffffffff 0 ffffffff [CHAR] 0 ff 0 ff The question is, is this a good thing? or a bad thing? Regan
Apr 07 2005
"Regan Heath" <regan netwin.co.nz> wrote in message news:opsouwe01t23k2f5 nrage.netwin.co.nz...The question is, is this a good thing? or a bad thing?It's a bad thing. It should be initialized to the .init value.
Apr 15 2005