c-for-go icon indicating copy to clipboard operation
c-for-go copied to clipboard

[question] generate Go function which accepts slice (without length) for C function that accepts dynamic array

Open laser opened this issue 5 years ago • 3 comments

Suppose a header file with the following:

typedef struct {
  uint8_t x;
} Flarp;

uint64_t foo(const Flarp *input_ptr, size_t input_len);

With no TRANSLATOR PtrTips specified, c-for-go generates the following Go signature:

func Foo(inputPtr []Flarp, inputLen uint) uint64 {

My question: Does there exist a configuration setting (in YAML) which will produce the following Go signature?

func Foo(inputPtr []Flarp) uint64 {

I would expect that the size_t input_len argument would be computed at runtime in the (automatically-generated) body (or some helper) of the Foo function.

laser avatar Mar 05 '20 22:03 laser

@laser did you ever find a solution to this?

karl-dau avatar Mar 23 '22 17:03 karl-dau

@karl-dau - Alas, I did not. If I recall correctly - and it's been a while now - we just ended up using func Foo(inputPtr []Flarp, inputLen uint) uint64 ~and ignoring the inputLen parameter~.

laser avatar Mar 23 '22 17:03 laser

Sorry for late reply lol. It wasn't possible since size is a very tricky thing in C, almost impossible to do it correctly automatically. There is a size tip but it has no real effect, just to mark things for better readability in YAML.

Screenshot 2022-03-27 at 23 22 07

Maybe it will be solved in the future.

xlab avatar Mar 27 '22 21:03 xlab