duan198299 2017-04-07 22:46
浏览 165
已采纳

意外的情况,编译时预期表达式错误

When I compile the following code, it generates

*syntax error: unexpected case, expecting expression* at line *case workerAddr = <- mr.registerChannel:*

I do not know why it happens since I just want to workerAddr to be set by either channel. Any suggestion will be appreciated.

for i:= 0; i < mr.nMap; i++ {   
    go func(jobCount) {
        for {
            var workerAddr string
            Select {
                // get a worker either from registerChannel or from idle channel
                case workerAddr = <- mr.registerChannel:
                case workerAddr = <- mr.idleChannel:
            } 
            // omit the following code
        }
    }(i)
}
  • 写回答

1条回答 默认 最新

  • duanbu1421 2017-04-08 00:29
    关注

    It happens because you have written Select when you should have written select.

    None of the Go keywords are capitalized, so when the compiler sees a capitalized word, it knows immediately that it's not an expression, and therefore a syntax error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习残差模块模型
  • ¥20 两个不同Subnet的点对点连接
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)