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

Accepted forward declared structs do not get a type in Go

Open CtrlZvi opened this issue 8 years ago • 2 comments

Forward declared (incomplete) structs will never have a type created for them in Go. This leads to generated code that cannot be compiled. I think it makes sense to generate them as a new named type with underlying type of the C.struct_* type would be a good way to handle it.

Example inputs that show the problem:

struct foo;

struct foo* bar();
// To define bar for test purposes
#include "test.h"

struct foo* bar() {
    return 0;
}
GENERATOR:
  PackageName: test
  Includes: ["test.h"]

PARSER:
  SourcesPaths: ["test.h"]

TRANSLATOR:
    MemTips:
      - {target: ^foo$, self: raw}
    Rules:
      type:
        - {action: accept, from: ^foo$}
      function:
        - {action: accept, from: ^bar$}

CtrlZvi avatar May 31 '17 22:05 CtrlZvi

Hm, this is strange, as I remember I actually complete the initial declaration once the body of the struct is available later.

See for example https://github.com/xlab/alac-go/blob/master/alac/alac.h#L6 is this the same case?

xlab avatar May 31 '17 22:05 xlab

Not quite. In this case the struct is never completed in the headers. It's only ever forward declared.

CtrlZvi avatar Jun 01 '17 00:06 CtrlZvi