golang/go

cmd/cgo: map sized integer types to C equivalents

Open

#29,878 opened on Jan 22, 2019

View on GitHub
 (13 comments) (1 reaction) (0 assignees)Go (19,008 forks)batch import
NeedsFixcompiler/runtimehelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

(Removing the template since this is an enhancement proposal)

The type mappings at https://golang.org/cmd/cgo/#hdr-Go_references_to_C don't state which Go types the sized C integer types int8_t etc. are mapped to. In C, these types have the same requirements as the corresponding Go types: they are not allowed to have padding bits and have to use two's complement representation, see https://en.cppreference.com/w/c/types/integer. Therefore, these types are guaranteed to have the same domain and representation as the corresponding Go types. So I propose to always represent these types with each other and formally document that fact. It would reduce the need for casts and would make it more obvious that there's no chance of data loss.

Contributor guide