Skip to content

cmd/cgo: enum constants with value of 0 are garbled if they are the only ones used #3821

@gopherbot

Description

@gopherbot

by mpvanlohuizen:

cmd/cgo: Consider the code below.  It will print 72057628379708111 instead of the
expected 0.  Uncomment the last line and everything works as expected.
I observed the bug only with enum values of 0.  As soon as another constant with a
non-zero value out of the same enum is used, all is good. Using multiple constants with
a value of 0 of the same enum does not fix the problem.  In this case, different values
may be printed in each case.

package main
/*
enum Const { ZERO, ONE, };
*/
import "C"
import "fmt"

func main() {
    fmt.Println(int64(C.ZERO))
    // fmt.Println(int64(C.ONE))
}

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Mac OS X Lion 10.7.4

Which version are you using?  (run 'go version')
go version weekly.2012-03-27 +2874979af37a

Please provide any additional information below.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions