Thread overview
Nice feature, but...
Apr 06, 2005
Andrew Fedoniouk
Apr 07, 2005
Ben Hinkle
Apr 07, 2005
Andrew Fedoniouk
Apr 07, 2005
Regan Heath
Apr 16, 2005
Walter
April 06, 2005
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.


April 07, 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.


April 07, 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.

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.


April 07, 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
April 16, 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.