c-for-go
c-for-go copied to clipboard
Accepted forward declared structs do not get a type in Go
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$}
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?
Not quite. In this case the struct is never completed in the headers. It's only ever forward declared.