Skip to content

Instantly share code, notes, and snippets.

@kostix
Created February 25, 2022 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kostix/4ef0cfddc4f06a06f3c9c3fa73cb278a to your computer and use it in GitHub Desktop.
Save kostix/4ef0cfddc4f06a06f3c9c3fa73cb278a to your computer and use it in GitHub Desktop.
package main
/*
#include <stdio.h>
struct real_client {
int x;
};
typedef struct Client{
struct real_client c;
} Client;
int doSomething(struct real_client *c) {
printf("%d\n", c->x);
}
*/
import "C"
type Client struct {
client C.Client
}
func main() {
cl := Client{}
cl.client.c.x = 42
C.doSomething(&cl.client.c)
}
module whatever
go 1.15
cgoptr$ ~/devel/golang-1.16.13/bin/go build
cgoptr$ GODEBUG=cgocheck=2 ./whatever
42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment