Created
September 21, 2013 07:03
-
-
Save tenntenn/6648005 to your computer and use it in GitHub Desktop.
[Go言語] constとiota面白い ref: http://qiita.com/tenntenn/items/0a3af58b225eeae29088
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
const ( | |
a = iota | |
b | |
c | |
) | |
func main() { | |
fmt.Println(a, b, c) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type flag uint | |
const ( | |
flag1 flag= iota << 1 | |
flag2 | |
flag3 | |
flag4 | |
bits = iota - 1 | |
mask = 1<<bits - 1 | |
) | |
func main() { | |
fmt.Printf("%b, %b, %b, %b, %d, %b", flag1, flag2, flag3, flag4, bits, mask) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment