=+ 是什么意思? (等于加)在C中是什么意思?
我今天在一些 C 代码中遇到了 =+
,而不是标准的 +=
;我不太确定这里发生了什么事。我在文档中也找不到它。
I came across =+
as opposed to the standard +=
today in some C code; I'm not quite sure what's going on here. I also couldn't find it in the documentation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在 C 的古代版本中,
=+
相当于+=
。它的残余物与最早的恐龙骨头一起被发现。[C 语言的发展,Dennis Ritchie。版权所有 ACM,1993。省略内部引用。]
自 20 世纪 70 年代中期以来,它没有特殊含义 —— 它只是一个
=
后面跟着一个+
。In ancient versions of C,
=+
was equivalent to+=
. Remnants of it have been found alongside the earliest dinosaur bones.[The Development of the C Language, Dennis Ritchie. Copyright ACM, 1993. Internal citations omitted.]
Since the mid-1970's, it has no special meaning -- it's just a
=
followed by a+
.您可以在 1979 年 1 月的第 7 版 UNIX 手册(第 2a 卷)中找到旧表示法的证据,该手册可在线访问 http://cm.bell-labs.com/7thEdMan/(大约自 2015 年 7 月起不再提供;2015 年 6 月的版本现已通过 WayBack Machine 提供: http://cm.bell-labs。 com/7thEdMan/ — 或位于 https://9p.io/7thEdMan/)。
该章的标题为 Dennis M. Ritchie 的“C 参考手册”,并且包含在该手册的 PDF 版本中,但没有 HTML 版本。
在相关部分,它说:
另外,L Rosler 在“UNIX® SYSTEM:阅读和应用,卷 II”中发表了一篇论文“C 的进化”,最初由 AT&T 作为其 1984 年 10 月的技术期刊出版,后来由 Prentice-Hall 于 1987 年出版(ISBN 0-13-939845-7)。其中一部分是:
III。管理不兼容的变更
Also, in
Brian W Kernighan and Dennis M Ritchie
The C Programming Language, 1st Edn (1978), on p212 in Appendix A, §17 Anachronisms, it says:
You can find evidence of the old notation in the 7th Edition UNIX Manual (Vol 2a) dated January 1979, available online at http://cm.bell-labs.com/7thEdMan/ (unavailable since approximately July 2015; the June 2015 version is now available via the WayBack Machine at http://cm.bell-labs.com/7thEdMan/ — or at https://9p.io/7thEdMan/).
The chapter is titled 'C Reference Manual' by Dennis M. Ritchie, and is in the PDF version of the manual, but not in the HTML version.
In the relevant part, it says:
Separately, there is a paper 'Evolution of C' by L Rosler in the 'UNIX® SYSTEM: Readings and Applications, Volume II', originally published by AT&T as their Technical Journal for October 1984, later published in 1987 by Prentice-Hall (ISBN 0-13-939845-7). One section of that is:
III. Managing Incompatible Changes
Also, in
Brian W Kernighan and Dennis M Ritchie
The C Programming Language, 1st Edn (1978), on p212 in Appendix A, §17 Anachronisms, it says:
它只是赋值后跟一元加。
打印“5”。将
a =+ 5
更改为a =- 5
并打印“-5”。更简单的读取a =+ 5
的方法可能是a = +5
。It's just assignment followed by unary plus.
Prints "5". Change
a =+ 5
toa =- 5
and it prints "-5". An easier way to reada =+ 5
is probablya = +5
.它是
+=
的古老变体。在现代编译器中,这相当于一个赋值运算符后跟一个一元+
。It's an ancient defunct variant of
+=
. In modern compilers, this is equivalent to an assignment operator followed by a unary+
.我认为
应该等同于
因此是风格非常糟糕的代码。
我尝试了以下代码并打印了“5”:
I think
should be equivalent to
and therefore be code of very bad style.
I tried the following code and it printed "5":
读完你的问题后,我刚刚调查了这些。让我告诉你我发现了什么。在 gcc 和turboc 上尝试过。没有在 Visual Studio 上确定,因为我还没有在我的 PC 上安装它,
我不知道其他答案,因为他们说它是 C 的古老版本。但是现代编译器将它们视为要分配的值(这是正数或仅此而已),下面的代码让我更加确定这一点。
After reading your question I just investigated on these. Let me tell you what I have found. Tried it on gcc and turboc. Did not make it sure on Visual Studio as I have not installed it on my pC
I dont know about the other answers as they said its an ancient version of C.But the modern compilers treat them as a value to be assigned ( thats positive or negative nothing more than that) and these below code makes me more sure about it.
使用“=+”您只是将操作数指定为正数
例如 int a = +10;与负数相同 int a = -10;
using "=+" you are just assigning the operand is positive
for example int a = +10; same as for negative number int a = -10;