如何从 K&RC 转换为 ANSI C?

发布于 2024-08-07 00:20:20 字数 881 浏览 3 评论 0原文

我正在尝试执行以下代码,这是 1988 年混淆 C 代码竞赛的参赛作品。

#define _ -F<00||--F-OO--;
int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()
{
            _-_-_-_
       _-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_
  _-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
  _-_-_-_-_-_-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_
        _-_-_-_-_-_-_-_
            _-_-_-_
}

从条目描述来看,这段代码是通过查看自己的面积来计算 pi 的。我没有修改代码就编译成功了。但是当我执行时,它给我的值为 0.25,我期望的是 3.14。代码描述说它在 K&RC 中,如果不进行一些更改,它在 ANSI C 中无法正常工作。我想我必须进行这些修改才能正确执行它。我以前没有任何使用 K&R C 的经验。所以有人可以帮助我将上面的代码更改为 ANSI C 或指出问题(如果有)。我正在使用 Microsoft Visual Studio 2008 来执行此操作。

I am trying to execute following code which is the 1988 entry of Obfuscated C Code Contest.

#define _ -F<00||--F-OO--;
int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()
{
            _-_-_-_
       _-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_
  _-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
  _-_-_-_-_-_-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_
        _-_-_-_-_-_-_-_
            _-_-_-_
}

From entry description, this code is calculating pi by looking at its own area. I successfully compiled it without changing the code. But when I executed, it is giving me a value 0.25, what I am expecting is 3.14. Code description says it is in K&R C and it doesn't work correctly in ANSI C without some change. I think I have to do those modification to execute it properly. I don't have any previous experience with K&R C. So can someone help me to change above code to ANSI C or point to the problems if any. I am using Microsoft Visual Studio 2008 to execute this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情未る 2024-08-14 00:20:20

如果您有 GCC,请使用“-traditional-cpp”标志进行编译。

区别在于“-_”序列是否转换为“- -F<00”或“--F<00”。

一个空格至关重要:它是双重否定和预自减之间的区别。

If you have GCC, compile with the '-traditional-cpp' flag.

The difference is whether the '-_' sequence is translated to '- -F<00' or '--F<00'.

The one space is crucial: it's the difference between double negation and pre-decrement.

深海夜未眠 2024-08-14 00:20:20

更改行:

#define _ F-->00 || F-OO--;

change the line:

#define _ F-->00 || F-OO--;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文