Void initialization

Stewart Gordon smjg_1998 at yahoo.com
Tue Dec 20 06:28:16 PST 2011


On 19/12/2011 12:12, bearophile wrote:
> Bear:
<snip>
>> float[] f = cast(float[])std.gc.malloc(x*4);
>
> Try something like this (untested):
>
> alias float TF;
> TF[] f = (cast(TF*)std.gc.malloc(x * TF.sizeof))[0 .. x];
<snip>

I fail to see any real difference from the OP's code:

- Why the alias?
- std.gc.malloc returns the array with correct length according to my quick test, so the 
use of [0..x] is redundant
- using TF.sizeof instead of 4 might fix things if on the user's platform float isn't 4 
bytes long.  Otherwise, while using .sizeof instead of a hard-coded number is better 
practice, it isn't going to get rid of an AV.

But knowing what platform the OP is using and having a complete testcase for the AVs/ABEs 
might help to understand what is going on.

Stewart.


More information about the Digitalmars-d-learn mailing list