www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - importC with struct name and function conflict

reply Dakota <dakota gmail.com> writes:
```c
struct type_name {
     int a;
}

int type_name(int a);

```

How can I get the function and type from importC?  is there a 
auto rename mechanism ?
Aug 02
parent reply Dennis <dkorpel gmail.com> writes:
On Saturday, 3 August 2024 at 05:10:37 UTC, Dakota wrote:
 How can I get the function and type from importC?  is there a 
 auto rename mechanism ?
The most pragmatic workaround is to add a typedef to the C code: ```C int S; struct S { int a, b; }; typedef struct S S_t; // add this typedef ``` https://dlang.org/spec/importc.html#tag-symbols
Aug 03
parent reply Dakota <dakota gmail.com> writes:
On Saturday, 3 August 2024 at 11:55:53 UTC, Dennis wrote:
 On Saturday, 3 August 2024 at 05:10:37 UTC, Dakota wrote:
 How can I get the function and type from importC?  is there a 
 auto rename mechanism ?
The most pragmatic workaround is to add a typedef to the C code: ```C int S; struct S { int a, b; }; typedef struct S S_t; // add this typedef ``` https://dlang.org/spec/importc.html#tag-symbols
Thanks for tips. This will not work for me. (huge code base I can not change and maintain)
Aug 05
parent reply Dennis <dkorpel gmail.com> writes:
On Monday, 5 August 2024 at 11:02:24 UTC, Dakota wrote:
 This will not work for me.  (huge code base I can not change 
 and maintain)
You don't have to change the code where the type is defined per se, you just need to put it in any C file that can access the C symbol. clib_helpers.c: ```C #include<hugelibrary.h> typedef struct S S_t; ``` app.d: ``` import clib_helpers; S_t s; ```
Aug 05
parent Dakota <dakota gmail.com> writes:
On Monday, 5 August 2024 at 11:35:56 UTC, Dennis wrote:
 On Monday, 5 August 2024 at 11:02:24 UTC, Dakota wrote:
 This will not work for me.  (huge code base I can not change 
 and maintain)
You don't have to change the code where the type is defined per se, you just need to put it in any C file that can access the C symbol. clib_helpers.c: ```C #include<hugelibrary.h> typedef struct S S_t; ``` app.d: ``` import clib_helpers; S_t s; ```
Thanks for the explain. I will think about this. my solution use ctfe symbol_name to get d define, and the symbol type name is get from ref place, (function arguments, struct field), so to fix it I need replace the type ref from headers files. In this case I get a wrong reflect type when I use `__traits(getMember, module, symbol);`
Aug 05