Thanks to visit codestin.com
Credit goes to github.com

Skip to content

proposal: cmd/cgo: add new names for //export and //extern #75439

@ianlancetaylor

Description

@ianlancetaylor

Proposal Details

The cgo tool uses two directives, //export and //extern, that do not follow the now-standard Go directive syntax. I propose that we replace them. For compatibility reasons we can't remove support for the old versions, but we can encourage people to move to the new ones.

The //export directive is used by cgo to indicate that a Go function should be made visible to C code. The format is //export NAME, where NAME is a C identifier. This means that C code can call the Go function by calling the function NAME.

I propose that we change this to //go:export. We should encourage new code to use //go;export NAME rather than //export NAME. We could make a modernizer for this that applies to files that import "C".

The //extern directive is specific to gccgo. It sets the name to use for the following function. Today it can be fully replaced by //go:linkname. I propose that we change cgo to emit an appropriate //go:linkname directive rather than a //extern directive. The few uses of //extern in Go source code can be rewritten manually to //go:linkname.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions