Can we use "ImportC" used yet?

jfondren julian.fondren at gmail.com
Sat Oct 16 11:03:06 UTC 2021


On Saturday, 16 October 2021 at 08:19:41 UTC, rempas wrote:
> On Saturday, 16 October 2021 at 07:09:16 UTC, jfondren wrote:
>>
>> This test_og.c works (while obviously breaking some bswap 
>> functions):
>
> I don't know if I should have known that but what is "bswap"?

I came up with those `#define`s by looking at test_c.c as d 
complained about it. It includes these functions in the final 
result:

```c
static __uint16_t
__bswap_16 (__uint16_t __bsx)
{
   return (__bsx);
}
static __uint32_t
__bswap_32 (__uint32_t __bsx)
{
   return (__bsx);
}
  static __uint64_t
__bswap_64 (__uint64_t __bsx)
{
   return (__bsx);
}
```

initially those were defined in terms of compiler intrinsics that 
d doesn't know about, and since they're not needed for your use, 
I fixed this in the direction of making them no-ops.

They're part of stdlib.h, probably. What they do is endian swaps, 
like the stuff in std.bitmanip

>> It would be less annoying to compile the original test_og.o 
>> with gcc and then link it in.
>
> If I understand correctly you mean compile the original file 
> with gcc (`gcc test_og.c -o test_og.o`) and then link it with 
> DMD (`dmd test.d test_og.o`)? Then what's the point of doing 
> that? Isn't this how we did that all this time and why ImportC 
> was created so we don't have to manually do the bindings? I'm 
> confused...

importC is a new option, but it doesn't make old options go away, 
and in this specific case an older option would've been less 
trouble. That's all I'm saying.


More information about the Digitalmars-d-learn mailing list