<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ### iota `iota`是`go`語言的常量計數器,只能在常量的表達式中使用 使用規則: * iota代表了const聲明塊的行索引(下標從0開始) 源碼: const塊中每一行在GO中使用spec數據結構描述,spec聲明如下: ~~~GO // A ValueSpec node represents a constant or variable declaration // (ConstSpec or VarSpec production). // ValueSpec struct { Doc *CommentGroup // associated documentation; or nil Names []*Ident // value names (len(Names) > 0) Type Expr // value type; or nil Values []Expr // initial values; or nil Comment *CommentGroup // line comments; or nil } ~~~ 這里我們只關注ValueSpec.Names, 這個切片中保存了一行中定義的常量,如果一行定義N個常量,那么ValueSpec.Names切片長度即為N。 const塊實際上是spec類型的切片,用于表示const中的多行。 所以編譯期間構造常量時的偽算法如下: ~~~GO for iota, spec := range ValueSpecs { for i, name := range spec.Names { obj := NewConst(name, iota...) //此處將iota傳入,用于構造常量 ... } } ~~~ 從上面可以更清晰的看出iota實際上是遍歷const塊的索引,每行中即便多次使用iota,其值也不會遞增 #### 示例一 使用_跳過某些值 ~~~ const ( n1 = iota //0 n2 //1 _ n4 //3 ) ~~~ `iota`聲明中間插隊 ~~~ const ( n1 = iota //0 n2 = 100 //100 n3 = iota //2 n4 //3 ) const n5 = iota //0 ~~~ 定義數量級 (這里的`<<`表示左移操作,`1<<10`表示將`1`的二進制表示向左移`10`位,也就是由`1`變成了`10000000000`,也就是十進制的`1024`。同理`2<<2`表示將`2`的二進制表示向左移`2`位,也就是由`10`變成了`1000`,也就是十進制的`8`。) ~~~ const ( _ = iota KB = 1 << (10 * iota) MB = 1 << (10 * iota) GB = 1 << (10 * iota) TB = 1 << (10 * iota) PB = 1 << (10 * iota) ) ~~~ 多個`iota`定義在一行 ~~~ const ( a, b = iota + 1, iota + 2 //1,2 c, d //2,3 e, f //3,4 ) ~~~ #### 示例二 ~~~go const ( mutexLocked = 1 << iota // mutex is locked mutexWoken mutexStarving mutexWaiterShift = iota starvationThresholdNs = 1e6 ) ~~~ 題目解釋: 以上代碼取自Go互斥鎖Mutex的實現,用于指示各種狀態位的地址偏移。 參考答案: mutexLocked == 1;mutexWoken == 2;mutexStarving == 4;mutexWaiterShift == 3;starvationThresholdNs == 1000000 #### 示例三 ~~~go const ( bit0, mask0 = 1 << iota, 1<<iota - 1 bit1, mask1 _, _ bit3, mask3 ) ~~~ 參考答案: bit0 == 1, mask0 == 0, bit1 == 2, mask1 == 1, bit3 == 8, mask3 == 7
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看