0

I want to use C library in Go. In order to execute C function I need to create C struct. I do it as follows:

package main

/*
#include <stdint.h>

typedef struct
{
    std::uint16_t x;
    std::uint16_t y;
} HeliosPoint;
*/
import "C"

import "fmt"

func main() {
    fmt.Println("hello world")
}

When I execute the code I got an error:

./main.go:8:2: error: expected specifier-qualifier-list before ‘std’
    8 |  std::uint16_t x;
      |  ^~~

How should I modify my code to use above struct?

trojek
  • 3,078
  • 2
  • 29
  • 52
  • 1
    Not sure why you have `std::` before the struct variable names. That's not valid C. What happends if you remove that from both the variables? – Inian Oct 27 '20 at 19:02
  • See - [golang struct with C struct in CGO](https://stackoverflow.com/q/54101022/5291015) – Inian Oct 27 '20 at 19:07
  • @Inian you were right, with `std::`, it isn't necessary. I removed it and it works. Thank you. – trojek Oct 27 '20 at 19:14

0 Answers0