What's best practice to use compound literals with structs and C-APIs?

Alex sascha.orlov at gmail.com
Wed May 1 19:13:54 UTC 2019


On Wednesday, 1 May 2019 at 14:59:48 UTC, Robert M. Münch wrote:
> On 2019-05-01 14:23:37 +0000, Alex said:
>
>> However, to rebuild the same structure, auto ref parameters 
>> may be appropriate.
>> https://dlang.org/spec/template.html#auto-ref-parameters
>
> That would need me to change myfunc which is not possible 
> because the D binding is all generated from C code.
>
Ok, I see.

>> or you new A(...) in place
>
> Doesn't work because this seems to kick in some D releated 
> run-time stuff which lead to unresolved externals during 
> linking:
>
> error LNK2001: Nicht aufgelöstes externes Symbol "...__initZ".
> error LNK2001: Nicht aufgelöstes externes Symbol 
> "...__xtoHashFNbNeKxSQBtQBoQBfZm".
> error LNK2001: Nicht aufgelöstes externes Symbol 
> "...__xopEqualsFKxSQBsQBnQBeKxQmZb".
>
> Not sure, why this happens.

Found this bug:
https://issues.dlang.org/show_bug.cgi?id=12374

It is closed now, because of inactivity, if you have a current 
case - a reopen is welcome.
However... Not sure, maybe someone else has more knowledge about 
this.

>
>> or you use the byRef-pattern as shown in d-idioms
>> https://p0nce.github.io/d-idioms/#Rvalue-references:-Understanding-auto-ref-and-then-not-using-it
>> 
>
> This again would need my to change the C bindings, which are 
> generated.

So, you generate D structs from C, right? If so, and if you need 
the byRef at any cost - you could tweak the generator, so byRef 
is generated for all structs.


More information about the Digitalmars-d-learn mailing list