new int[]

2018-01-10 Thread Luís Marques via Digitalmars-d-learn
the wrapper? `new int[]` isn't supported, even though that's exactly what I want.

Re: new int[]

2018-01-10 Thread Luís Marques via Digitalmars-d-learn
On Wednesday, 10 January 2018 at 22:35:01 UTC, Luís Marques wrote: How can I do that without the wrapper? `new int[]` isn't supported, even though that's exactly what I want. Just to be extra clear: I really do want a normal D slice, it can't be a fixed-length array.

Re: new int[]

2018-01-10 Thread ag0aep6g via Digitalmars-d-learn
;     writeln(context.x);     } How can I do that without the wrapper? `new int[]` isn't supported, even though that's exactly what I want. If I understand correctly, the goal is to have the `int[]` itself on the GC heap. You can make an `int[][]` with one element, and then take the addre

Re: new int[]

2018-01-10 Thread Nathan S. via Digitalmars-d-learn
Is there any problem with: import std.stdio; void main(string[] args) { int[] x = [1, 2, 3]; writeln(x); } https://run.dlang.io/is/CliWcz

Re: new int[]

2018-01-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 10 January 2018 at 22:46:30 UTC, ag0aep6g wrote: If I understand correctly, the goal is to have the `int[]` itself on the GC heap. General word of warning: if you pass it to C and the C function holds on to that pointer for any reason beyond its immediate execution, you could be

Re: new int[]

2018-01-10 Thread Ali Çehreli via Digitalmars-d-learn
context = cast(Wrapper*) ctxptr; writeln(context.x); } How can I do that without the wrapper? `new int[]` isn't supported, even though that's exactly what I want. If I understand correctly, the goal is to have the `int[]` itself on the GC heap. You can make an `int[][]

Re: new int[]

2018-01-10 Thread Nathan S. via Digitalmars-d-learn
On Wednesday, 10 January 2018 at 22:46:30 UTC, ag0aep6g wrote: If I understand correctly, the goal is to have the `int[]` itself on the GC heap. The code void main(string[] args) @nogc { int[] x = [1, 2, 3]; } won't compile, because "array literal in @nogc function 'D main' may

Re: new int[]

2018-01-10 Thread Luís Marques via Digitalmars-d-learn
On Wednesday, 10 January 2018 at 22:48:48 UTC, Adam D. Ruppe wrote: General word of warning: if you pass it to C and the C function holds on to that pointer for any reason beyond its immediate execution, you could be looking at a problem because the D GC can't see C function memory and may free

Re: new int[]

2018-01-10 Thread Luís Marques via Digitalmars-d-learn
On Wednesday, 10 January 2018 at 22:46:30 UTC, ag0aep6g wrote: If I understand correctly, the goal is to have the `int[]` itself on the GC heap. That's correct. You can make an `int[][]` with one element, and then take the address of that element: void main() { int[]* x = &[[1, 2, 3]][0

Re: new int[]

2018-01-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 10, 2018 22:50:22 Nathan S. via Digitalmars-d-learn wrote: > On Wednesday, 10 January 2018 at 22:46:30 UTC, ag0aep6g wrote: > > If I understand correctly, the goal is to have the `int[]` > > itself on the GC heap. > > The code > > void main(string[] args) @nogc > { >

Re: new int[]

2018-01-11 Thread Dukc via Digitalmars-d-learn
On Wednesday, 10 January 2018 at 23:08:28 UTC, Luís Marques wrote: void main() { int[]* x = &[[1, 2, 3]][0]; int[]* x2 = [[1, 2, 3]].ptr; /* same */ } That's an interesting solution. I'm not sure which one I prefer, the wrapper or this one. Still... I feel like the language should just

auto arr = new int[10];

2011-04-16 Thread %u
is there any different b/w: auto arr = new int[10]; and int[10] arr; ?

Re: auto arr = new int[10];

2011-04-16 Thread Piotr Szturmaj
%u wrote: is there any different b/w: auto arr = new int[10]; arr is dynamic array of int with ten elements and int[10] arr; ? arr is static array of int with ten elements