这个问题在这里已经有了答案:
1998 vintage C code now fails to compile under gcc
(2 个回答)
1年前关闭。
来自 1987 年 IOCCC 的这条回文词条:
https://www.ioccc.org/years.html#1987_westley
...在默认编译期间导致 TCC 0.9.27 没有问题并按预期工作。
然而,GCC 9.3.0,即使在 -std=c89
模式,提示以下 (int) (tni)
的实例不是左值:
for (; (int) (tni);)
(int) (tni) = reviled;
^
(lvalue required as left operand of assignment)
...
for ((int) (tni)++, ++reviled; reviled * *deliver; deliver++, ++(int) (tni))
^~
(lvalue required as increment operand)
(美化代码以获得更好的上下文)我目前的想法:
在
=
在这种情况下,我怀疑使用 (int) (tni) 作为 for
中的条件循环取消它作为左值的资格,但我不确定。在
++
在这种情况下,我稍后可以在该代码中看到它的回文性质如何迫使作者使用 --
(int) 和 (tni) 之间的运算符,这不被视为问题。所以 GCC 需要 ++
运算符就在变量之前,而不是在它的强制转换之前,而是用左值提示暗示了这个要求。这些 GCC 投诉是否有明确的答案? TCC 是不是太松懈了?
提前致谢!
编辑:我很高兴地指出了一个类似的问题,它在这里回答了类型转换问题 - 请参阅下面的我的评论以获取解决方案!
最佳答案
众所周知,TCC 不是符合标准的 C 实现 - TCC 试图成为小型且快速的编译器,尝试编译正确的 C 代码,并且它通常不会产生标准所需的诊断。更广为人知的是,第一个 C 标准于 1989 年问世,而最广为人知的是 1987 年早于 1989 年。
C11 6.5.4p5 :
- Preceding an expression by a parenthesized type name converts the value of the expression to the named type. This construction is called a cast. 104) A cast that specifies no conversion has no effect on the type or value of an expression.
脚注 104 指出:
- A cast does not yield an lvalue. Thus, a cast to a qualified type has the same effect as a cast to the unqualified version of the type.
对于赋值运算符,6.5.16p2 说:
- An assignment operator shall have a modifiable lvalue as its left operand.
6.5.16p2 在约束部分,因此必须诊断违规。
关于c - IOCCC 1987/weSTLey.c - GCC 的左值问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64369667/