码迷,mamicode.com
首页 > 其他好文 > 详细

golang的++与--

时间:2016-09-07 14:24:05      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

http://godoc.golangtc.com/doc/faq#inc_dec

简单地说, 在golang中++,--操作是语句而不是表达式. 所以a=b++, return x++之类绝对提示错误. 语句是无法放到表达式的位置

Why are ++ and -- statements and not expressions? And why postfix, not prefix?

Without pointer arithmetic, the convenience value of pre- and postfix increment operators drops. By removing them from the expression hierarchy altogether, expression syntax is simplified and the messy issues around order of evaluation of ++ and --(consider f(i++) and p[i] = q[++i]) are eliminated as well. The simplification is significant. As for postfix vs. prefix, either would work fine but the postfix version is more traditional; insistence on prefix arose with the STL, a library for a language whose name contains, ironically, a postfix increment.

golang的++与--

标签:

原文地址:http://www.cnblogs.com/zolo/p/5849116.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!