• Gustavo Niemeyer's avatar
    cgo: fix handling of signed enumerations · 45217825
    Gustavo Niemeyer authored
    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
    45217825
gcc.go 30.6 KB