atilaneves / dpp

Directly include C headers in D source code
Boost Software License 1.0
230 stars 31 forks source link

Correct behavior for functions implemented in header files #243

Open andre2007 opened 4 years ago

andre2007 commented 4 years ago

See here for an example

https://github.com/Azure/azure-sdk-for-c/blob/master/sdk/core/core/inc/az_span.h#L91

AZ_NODISCARD AZ_INLINE az_span az_span_init(uint8_t * ptr, int32_t length, int32_t capacity) {
  return (az_span){ ._internal = { .ptr = ptr, .length = length, .capacity = capacity, }, };
}

As it is an inline function and defined and implemented in the header file, it wont be in the fields symbols of the resulting static/dynamic library. Therefore linker will always fail. It has to be implemented in D coding (in the DPP module like for macros)

I wonder what is the correct behavior for Dpp. At the moment the signature is added in the generated module, with extern(C) declaration.

atilaneves commented 4 years ago

There's a workaround which is to make the C compiler emit code for this in a C translation unit and link to that. Translating arbitrary C code is going to take a lot of work.