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

cannot use TypedefDecl for DeclStmt #272

Closed
yulvil opened this issue Oct 24, 2017 · 2 comments
Closed

cannot use TypedefDecl for DeclStmt #272

yulvil opened this issue Oct 24, 2017 · 2 comments

Comments

@yulvil
Copy link
Contributor

yulvil commented Oct 24, 2017

C

int main() {
    struct node { int kind; int val; };
    typedef struct node node;

    node n;
    n.kind = 10;
    n.val = 20;
    return n.kind;
}

Go (current)

// Warning (TypedefDecl): %!s(int=3): cannot use TypedefDecl for DeclStmt
// Warning (VarDecl): %!s(int=5): I couldn't find an appropriate Go type for the C type 'node'.
// Warning (MemberExpr): %!s(int=6): I couldn't find an appropriate Go type for the C type 'node'.
// Warning (MemberExpr): %!s(int=6): cannot determine type for LHS 'node', will use 'void *' for all fields
// Warning (MemberExpr): %!s(int=7): I couldn't find an appropriate Go type for the C type 'node'.
// Warning (MemberExpr): %!s(int=7): cannot determine type for LHS 'node', will use 'void *' for all fields
// Warning (MemberExpr): %!s(int=8): I couldn't find an appropriate Go type for the C type 'node'.
// Warning (MemberExpr): %!s(int=8): cannot determine type for LHS 'node', will use 'void *' for all fields

package main

import "os"
import "github.com/elliotchance/c2go/noarch"

type __int128_t int64
type __uint128_t uint64

func main() {
        __init()
        var n interface {
        }
        n.kind = 10
        n.val = 20
        os.Exit(noarch.ByteSliceToInt(n.kind))
}
func __init() {
}
@yulvil
Copy link
Contributor Author

yulvil commented Oct 24, 2017

It looks like the struct cannot be defined inside a function. If I move both the struct definition and the typedef outside the function then it works:

C

struct node { int kind; int val; };
typedef struct node node;

int main() {

    node n;
    n.kind = 10;
    n.val = 20;
    return n.kind;
}

Go

package main

import "os"

type __int128_t int64
type __uint128_t uint64
type node struct {
        kind int
        val  int
}

func main() {
        __init()
        var n node
        n.kind = 10
        n.val = 20
        os.Exit(n.kind)
}
func __init() {
}

@yulvil
Copy link
Contributor Author

yulvil commented Nov 1, 2017

A smaller example (without the struct)

int main() {
	typedef int myint;
	myint x = 123;
	return x;
}

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

1 participant