importC error Error: undefined identifier `__builtin_unreachable`

2024-02-26 Thread Dakota via Digitalmars-d-learn
I try one more importC case, get this error: ```sh Error: undefined identifier `__builtin_unreachable` ``` any tips to fix this?

Re: importC error Error: undefined identifier `__builtin_unreachable`

2024-02-26 Thread Dakota via Digitalmars-d-learn
On Monday, 26 February 2024 at 08:18:53 UTC, Richard (Rikki) Andrew Cattermole wrote: On 26/02/2024 9:04 PM, Dakota wrote: I try one more importC case, get this error: ```sh Error: undefined identifier `__builtin_unreachable` ``` any tips to fix this? Reported: https://issues.dlang.org/show

importC with gc-sections not work on linux

2024-02-26 Thread Dakota via Digitalmars-d-learn
When I use importC to build a c library, there is a lot unused symbol missing. I try add `-L--gc-sections` to dmd to workaround this issue. I also try `-L-dead_strip` on macOS, it work as expected. I do some google, some one suggestion use with `-ffunction-sections`, `-f fdata-sections`, d

Re: importC with gc-sections not work on linux

2024-02-26 Thread Dakota via Digitalmars-d-learn
On Monday, 26 February 2024 at 12:33:02 UTC, Richard (Rikki) Andrew Cattermole wrote: On 27/02/2024 1:28 AM, Dakota wrote: When I use importC to build a c library, there is a lot unused symbol missing. I try add `-L--gc-sections` to dmd to workaround this issue. This removes symbols, not kee

Re: need help with simple importC

2024-02-26 Thread Dakota via Digitalmars-d-learn
On Monday, 26 February 2024 at 07:44:02 UTC, Dakota wrote: I am use importC from linux, get this error: ```sh /usr/include/x86_64-linux-gnu/bits/floatn-common.h(214): Error: illegal combination of type specifiers /usr/include/x86_64-linux-gnu/bits/floatn-common.h(251): Error: illegal combinat

question about ctfe init importC zero length array of struct

2024-02-28 Thread Dakota via Digitalmars-d-learn
This is the type defined from c code import by importC: ```c struct A { int count; int[] i; } ``` This kind data need to be init as const to avoid runtime cost, and need to be done from D code. how can I do this ? To put code into D source, I can use "-i=package" to automatically

need help to use C++ callback from garnet

2024-05-29 Thread Dakota via Digitalmars-d-learn
I try use https://github.com/microsoft/garnet/blob/main/libs/storage/Tsavorite/cc/src/device/native_device_wrapper.cc from D Not sure how to make this work with D: ```c++ EXPORTED_SYMBOL FASTER::core::Status NativeDevice_ReadAsync(NativeDevice* device, uint64_t source, void* dest, uint32_t

Re: need help to use C++ callback from garnet

2024-06-04 Thread Dakota via Digitalmars-d-learn
On Wednesday, 29 May 2024 at 09:01:13 UTC, evilrat wrote: On Wednesday, 29 May 2024 at 07:47:01 UTC, Dakota wrote: [...] (here is the signature of callback) https://github.com/microsoft/garnet/blob/ade2991f3737b9b5e3151d0dd0b614adfd4bcecd/libs/storage/Tsavorite/cc/src/device/async.h#L25 [...

need help to check symbol is static variable or not

2024-07-01 Thread Dakota via Digitalmars-d-learn
this code give error: ```d static if( !__traits(compiles, mixin("enum v = V;")) ) { enum v = V; } ``` ```sh Error: static variable `NotWorkVar` cannot be read at compile time ``` V is alias get from `typeof(__traits(getMember, M, symbol)`, M is `module` from importC. the importC so

Re: need help to check symbol is static variable or not

2024-07-01 Thread Dakota via Digitalmars-d-learn
On Monday, 1 July 2024 at 11:15:46 UTC, Nick Treleaven wrote: On Monday, 1 July 2024 at 07:32:30 UTC, Dakota wrote: this code give error: ```d static if( !__traits(compiles, mixin("enum v = V;")) ) { enum v = V; } ``` __traits(compiles, ...) can't check if a declaration is valid directl

Re: need help to get bitoffsetof bitwidth for clang

2024-07-04 Thread Dakota via Digitalmars-d-learn
On Wednesday, 3 July 2024 at 21:47:32 UTC, Tim wrote: If you only want to see the layout, you can use the following command to dump it: ``` clang test.c -Xclang -fdump-record-layouts -c ``` File test.c could contain the following: ``` struct S { int a : 3; int b : 29; }; struct S dummy;

Re: need help to check symbol is static variable or not

2024-07-14 Thread Dakota via Digitalmars-d-learn
On Monday, 1 July 2024 at 11:15:46 UTC, Nick Treleaven wrote: ``` There is a case check will give wrong resutls: ```d struct type_s { union { struct { int a; int b; } c; }; }; ``` `type c` will return false with `enum isStatic(alias V

Re: need help to check symbol is static variable or not

2024-07-15 Thread Dakota via Digitalmars-d-learn
On Monday, 15 July 2024 at 11:16:23 UTC, Nick Treleaven wrote: I put `type_s` in a file anonstruct.c, then: ```d import anonstruct; pragma(msg, isStatic!(type_s.c)); ``` That outputs `false`, because the symbol is not a compile-time value. Is that what you meant? No, I am here deal with a lo

Error: circular reference to variable cause by order (bugs?)

2024-07-18 Thread Dakota via Digitalmars-d-learn
I am trying to translate some c code into d, get this error: ```d struct A { void* sub; } struct B { void* subs; } __gshared { const A[1] a0 = [ { &b1_ptr }, ]; const A[2] a1 = [ { &b1_ptr }, ]; const B b1 =

importC error: can not find the #define ERR_INVALID -1

2024-08-02 Thread Dakota via Digitalmars-d-learn
```c #define ERR_SUCCESS 0 #define ERR_INVALID -1 // invalid argument ``` If the number >=0, it work. < 0 will not work. DMD64 D Compiler v2.110.0-beta.1

importC with struct name and function conflict

2024-08-02 Thread Dakota via Digitalmars-d-learn
```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 ?

Re: importC with struct name and function conflict

2024-08-05 Thread Dakota via Digitalmars-d-learn
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

Re: importC with struct name and function conflict

2024-08-05 Thread Dakota via Digitalmars-d-learn
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

importC error: alignment value expected, not `sizeof`

2024-08-07 Thread Dakota via Digitalmars-d-learn
```c typedef struct test_s { unsigned char _[64] __attribute__ ((aligned (sizeof (void *; } test_t; ```

importC error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/vm_types.h(168): Error: variable `lib_test.mach_vm_range_recipe_v1_t.ra

2024-08-07 Thread Dakota via Digitalmars-d-learn
```sh /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/vm_types.h(168): Error: variable `lib_test.mach_vm_range_recipe_v1_t.range` - no definition of struct `mach_vm_range` /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.

inportC with postgres 16_4 on macOS error

2024-08-08 Thread Dakota via Digitalmars-d-learn
dmd v2.110.0-beta.1 ```sh /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h(145): Error: found `__filename` when expecting `,` /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/inc

Re: inportC with postgres 16_4 on macOS error

2024-08-08 Thread Dakota via Digitalmars-d-learn
On Thursday, 8 August 2024 at 10:08:18 UTC, Dakota wrote: dmd v2.110.0-beta.1 ```c #if defined(_DARWIN_UNLIMITED_STREAMS) || defined(_DARWIN_C_SOURCE) FILE*fopen(const char * __restrict __filename, const char * __restrict __mode) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_3_2, __DAR

Re: need help to use Emscripten with LDC to build wasm projects

2024-08-22 Thread Dakota via Digitalmars-d-learn
On Thursday, 22 August 2024 at 21:19:57 UTC, monkyyy wrote: On Thursday, 22 August 2024 at 07:28:00 UTC, Dakota wrote: Is there a way to link ldc objects with Emscripten to build wasm binary ? yes; you'll have to untangle my build system https://github.com/crazymonkyyy/raylib-2024 It will al