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 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?

SDB@79


Re: Variable length arrays under -betterC?

2023-04-17 Thread user456 via Digitalmars-d-learn

On Monday, 17 April 2023 at 18:34:19 UTC, DLearner wrote:
Requirement is to write some D code (which avoids the GC), that 
will be called from C.
So simple approach seemed to be to write D code under -betterC 
restrictions.


However, also need variable length arrays - but D Dynamic 
Arrays not 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;

public:

size_t length() {
return p.length;
}

void length(size_t v) {
import core.stdc.stdlib;
p.ptr = cast(T*) realloc(p.ptr, v * T.sizeof);
}

ref T opIndex(size_t i) {
return p.ptr[i];
}
}

void main()
{
Array!int a;
}
```

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.

Maybe try to find an already existing one;

https://github.com/gilzoide/betterclist
https://github.com/aferust/dvector
(maybe more in https://code.dlang.org/search?q=betterc)


Variable length arrays under -betterC?

2023-04-17 Thread DLearner via Digitalmars-d-learn
Requirement is to write some D code (which avoids the GC), that 
will be called from C.
So simple approach seemed to be to write D code under -betterC 
restrictions.


However, also need variable length arrays - but D Dynamic Arrays 
not allowed under -betterC.

So tried trivial example using std.container:
```
extern(C) void main() {

   import std.container;

   auto arr = Array!int(0, 2, 3);
}
```
compiled with:
```
dmd -betterC -run Array_ex_01v00
```
Which failed with:
```
C:\D\dmd2\windows\bin\..\..\src\druntime\import\core\internal\array\construction.d(207):
 Error: cannot use try-catch statements with -betterC
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(151): Error: 
template instance 
`core.internal.array.construction._d_arraysetctor!(const(Array!int)[], 
const(Array!int))` error instantiating
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(244):
instantiated from here: `RangeT!(const(Array!int))`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(633):
instantiated from here: `RangeT!(Array!int)`
Array_ex_01v00.d(5):instantiated from here: `Array!int`
C:\D\dmd2\windows\bin\..\..\src\druntime\import\core\internal\array\construction.d(207):
 Error: cannot use try-catch statements with -betterC
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(151): Error: 
template instance 
`core.internal.array.construction._d_arraysetctor!(immutable(Array!int)[], 
immutable(Array!int))` error instantiating
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?


Re: Unresolvable dependencies to package

2023-04-17 Thread Luna via Digitalmars-d-learn

On Saturday, 15 April 2023 at 00:48:21 UTC, Mike Parker wrote:

On Saturday, 15 April 2023 at 00:42:17 UTC, Mike Parker wrote:

I also suggest you visit the issues page for bindbc-imgui and 
file an issue there:


I meant to delete this line. I've filed the issue:

https://github.com/BindBC/bindbc-imgui/issues/1


Inochi Creator is additionally not meant to be used as a package, 
if you want to use Inochi2D in your game or software you want the 
inochi2d package, then provide your own OpenGL 3.1 context.