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

cmd/cgo: C code with function taking pointer typedef leads to C compiler warning #19832

ianlancetaylor opened this Issue Apr 4, 2017 · 3 comments


None yet
3 participants

ianlancetaylor commented Apr 4, 2017

Building this file gets a warning from the C compiler:

package main

// typedef struct { int i; } *PS;
// void F(PS p) {}
import "C"

func main() {

The warning I see is:

# command-line-arguments
cgo-gcc-prolog: In function ‘_cgo_0164fa09626e_Cfunc_F’:
cgo-gcc-prolog:37:2: warning: passing argument 1 of ‘F’ from incompatible pointer type [enabled by default]
/home/iant/foo8.go:4:7: note: expected ‘PS’ but argument is of type ‘struct <anonymous> *’
 // void F(PS p) {}

The code generated by cgo looks like:

_cgo_0164fa09626e_Cfunc_F(void *v)
	struct {
		struct {int i; }* p0;
	} __attribute__((__packed__, __gcc_struct__)) *a = v;

The C function expects PS* but we are passing struct{int i;}*. That is, we aren't using the typedef.

Changing the Go code to use C.PS(unsafe.Pointer(nil)) also fails in the same way.


This comment has been minimized.

gopherbot commented Jul 18, 2017

CL mentions this issue.


This comment has been minimized.

gopherbot commented Feb 6, 2018

Change mentions this issue: cmd/cgo: revert CL 49490 "fix for function taking pointer typedef"

gopherbot pushed a commit that referenced this issue Feb 7, 2018

cmd/cgo: revert CL 49490 "fix for function taking pointer typedef"
CL 49490 fixed a warning when compiling the C code generated by cgo,
but it introduced typedef conflicts in Go code that cgo is supposed to

Original CL description:

    cmd/cgo: fix for function taking pointer typedef

    Fixes #19832

Updates #19832
Fixes #23720

Change-Id: I22a732db31be0b4f7248c105277ab8ee44ef6cfb
Run-TryBot: Ian Lance Taylor <>
TryBot-Result: Gobot Gobot <>
Reviewed-by: Austin Clements <>

This comment has been minimized.


ianlancetaylor commented Feb 7, 2018

Reopening to fix in 1.11, without breaking #23720 .

@ianlancetaylor ianlancetaylor reopened this Feb 7, 2018

@ianlancetaylor ianlancetaylor modified the milestones: Go1.10, Go1.11 Feb 7, 2018

@gopherbot gopherbot modified the milestones: Go1.11, Unplanned May 23, 2018

Gskartwii added a commit to Gskartwii/windivert-go that referenced this issue Nov 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment