Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accepted forward declared structs do not get a type in Go #33

Open
CtrlZvi opened this issue May 31, 2017 · 2 comments
Open

Accepted forward declared structs do not get a type in Go #33

CtrlZvi opened this issue May 31, 2017 · 2 comments

Comments

@CtrlZvi
Copy link

CtrlZvi commented May 31, 2017

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$}
@xlab
Copy link
Owner

xlab commented May 31, 2017

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?

@CtrlZvi
Copy link
Author

CtrlZvi commented Jun 1, 2017

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

@CtrlZvi CtrlZvi closed this as completed Jun 1, 2017
@CtrlZvi CtrlZvi reopened this Jun 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants