Le lundi 4 juillet 2016 02:25:06 UTC, Jingguo Yao a écrit :
>
> Take the following code as an example:
>
>
> package main
> import (
>   "fmt"
> )
> const (
>   First int64 = iota
>   Second
> )
> const (
>   One int64 = 1
>   Two = 2
> )
> func main() {
>   fmt.Printf("First type: %T, Second type: %T\n", First, Second)
>   fmt.Printf("One type: %T, Two type: %T\n", One, Two)
> }
>
>
> Running the above code produces:
>
>
> First type: int64, Second type: int64
> One type: int64, Two type: int
>
>
> Why is Second's type int64 instead of the default type int like Two? I 
> think
> that it is decided by the following rule from 
> https://golang.org/ref/spec#Constant_declarations. Is my understanding
> correct?
>
>
> > Within a parenthesized const declaration list the expression list
> > may be omitted from any but the first declaration. Such an empty
> > list is equivalent to the textual substitution of the first
> > preceding non-empty expression list and its type if any. Omitting
> > the list of expressions is therefore equivalent to repeating the
> > previous list. The number of identifiers must be equal to the number
> > of expressions in the previous list.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to