]> Cypherpunks repositories - gostls13.git/commit
cgo: fix handling of signed enumerations
authorGustavo Niemeyer <gustavo@niemeyer.net>
Wed, 9 Feb 2011 04:50:14 +0000 (23:50 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 9 Feb 2011 04:50:14 +0000 (23:50 -0500)
commit4521782514725fb4ac904c545e58ba0959148925
treec9bdddfa0e0611a1eb9fb3e1696625e9c5f4f480
parent2aaabfc828268c93d7d242f570f2dade1397b6f4
cgo: fix handling of signed enumerations

Structs defined in C as containing a field with
an enum type are currently translated to Go as
a struct with an unsigned integer field, even if
some of the values contained in the enum are
negative.

This modification takes in consideration the values
defined in the enum, and conditionally defines the
Go type as signed if necessary.

The logic introduced was tested with gcc, which
will increase the type size if it contains both
negative numbers and values greater than 2^b/2-1,
and refuses to compile values which would be
problematic (2^64-1, but in fact the ISO C
restricts the range to the size of int).

R=rsc
CC=golang-dev
https://golang.org/cl/4119058
src/cmd/cgo/gcc.go