Re: Variable length arrays under -betterC?

2023-04-18 Thread Steven Schveighoffer via Digitalmars-d-learn
. Any ideas how to implement variable length arrays under -betterC? variable-length arrays (i.e. slices) are valid in betterC. What isn't allowed is *GC-allocating* them and *appending* to them in betterC. ```d int[] arr; // fine // arr ~= 5; // nope, uses GC arr = (cast(int *)m

Re: Variable length arrays under -betterC?

2023-04-18 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 18 April 2023 at 06:20:43 UTC, Richard (Rikki) Andrew Cattermole wrote: On 18/04/2023 1:33 PM, Salih Dincer wrote: I understand from the thread this: D gives us -betterC but nothing from the Phobos.  So he says, see what you have, do what the hell you want! Am I wrong about this?

Re: Variable length arrays under -betterC?

2023-04-17 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 18/04/2023 1:33 PM, Salih Dincer wrote: I understand from the thread this: D gives us -betterC but nothing from the Phobos.  So he says, see what you have, do what the hell you want! Am I wrong about this? Nope. -betterC means you have no runtime or standard library support. You are very

Re: Variable length arrays under -betterC?

2023-04-17 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 17 April 2023 at 19:12:20 UTC, user456 wrote: ... but you'll have to implement - ctors - concat assign - slice assign - copy construction - value type elem alignment - default elem construction - default elem destruction - etc. to make that usable in on trivial cases. I understand

Re: Variable length arrays under -betterC?

2023-04-17 Thread user456 via Digitalmars-d-learn
allowed under -betterC. [...] Any ideas how to implement variable length arrays under -betterC? You need a struct with operator overloads and libc realloc(), (very) basically ```d struct Array(T) { private: struct Payload { T* ptr; size_t length; } Payload p

Variable length arrays under -betterC?

2023-04-17 Thread DLearner via Digitalmars-d-learn
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(639): instantiated from here: `RangeT!(immutable(Array!int))` Array_ex_01v00.d(5):instantiated from here: `Array!int` ``` Any ideas how to implement variable length arrays under -betterC?