Re: SumType! seemingly results in cryptic error, with dub suggesting to make an issue ticket

2023-05-30 Thread user456 via Digitalmars-d-learn

On Tuesday, 30 May 2023 at 08:42:38 UTC, Gimbles wrote:

My code is this
[...]
Should I make an issue for this as it suggests?


100% yes. This an "Internal Compiler Error" (ICE), meaning the 
compiler has crashed.
Open a ticket here : 
https://issues.dlang.org/show_bug.cgi?id=23935


with a title like "ICE caused by std.sumtype", and paste the test 
case.


Re: Best way to use C library

2023-05-19 Thread user456 via Digitalmars-d-learn

On Friday, 19 May 2023 at 18:31:45 UTC, Maximilian Naderer wrote:

Hello guys,

So what’s currently the best way to use a big C library?

Let’s assume something like

cglm
assimp
glfw

ImportC doesn’t really work for such huge libraries, I’ll 
investigate further. Deimos is outdated or there are no 
bindings. I know that there is a dub package for glfw which 
works fine. But how would I do something for assimp or cglm. 
The dub assimp package is quite outdated.


Am I stuck with manually creating interface files either by 
hand or automation?


I’m hope somebody could give me some insights. Thank you !

Kind regards from Austria
Max


If you aim static linking or static binding then you can give 
[dstep](https://github.com/jacob-carlborg/dstep) a shot.


Otherwise and if you have the time to then dont forget to report 
the problems founds

when you have tried ImportC.


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)


Re: how to use unknown size of array at compile time for further processing

2017-10-01 Thread user456 via Digitalmars-d-learn

On Sunday, 1 October 2017 at 10:07:40 UTC, thorstein wrote:

Hi,
assumed, I need the size of a dynamic array for further 
processing, which is unknown at compile time. Below are my 
example, which doesn't work and two alternatives.


[...]


They are not alternatives. They are the only way of doing things.