Skip to content

cgo only supports integer-sized parameters #4489

Open
@Leopotam

Description

@Leopotam
// native.h
typedef struct Vector2
{
    float x;
    float y;
} Vector2;

Vector2 Vector2Add(Vector2 v1, Vector2 v2)
{
    Vector2 result = {v1.x + v2.x, v1.y + v2.y};
    return result;
}
// main.go
package main

// #include "native.h"
import "C"
import "fmt"

func main() {
	a := C.Vector2{1, 2}
	b := C.Vector2{1, 2}
	c := C.Vector2Add(a, b)
	fmt.Println(c)
}
> go run main.go
{2 4}
> tinygo run main.go
{3 2}
> tinygo version
tinygo version 0.33.0 darwin/amd64 (using go version go1.23.2 and LLVM version 18.1.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcgoCGo and libc related issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions