importC reflection drop const attribute bugs

Dakota dakota at gmail.com
Wed Feb 28 05:41:21 UTC 2024


On Wednesday, 28 February 2024 at 05:13:19 UTC, Dave P. wrote:
> On Wednesday, 28 February 2024 at 05:00:32 UTC, Dakota wrote:
>> [...]
>
> I reported this as a bug before: 
> https://issues.dlang.org/show_bug.cgi?id=23926
>
> It’s actually not clear what the solution should be as D const 
> is not the same as C const as D const is transitive. Walter 
> decided to err on the side of accepting more code, so C const 
> is translated to D non-const.

Thanks for the tips.


I am work on a big code base, it use C const as transitive( so 
the function accept const will not change the pointer field).


`C const translated to D non-const` not a good solution for me.

I suggestion add a dmd flags to change the behavior,  like 
`--importC-const-pointer=`.  so the user can choice what kind 
behavior they want.


some project use transitive const in C, so they can work with 
this new options.


One more options is translate it into a user-defined template, 
this is more flexible.  user can return diff result base on the 
name. for example:


```c
typedef struct Message Message;
int tryEncode(const Message* msg);
```

=>

```d
struct Message;
int tryEncode(importConstPointer!(Message)* msg);
```




More information about the Digitalmars-d mailing list