这个程序的流程是什么?

发布于 2024-11-15 10:55:08 字数 908 浏览 3 评论 0原文

我遇到了一段让我困惑的 cobol 程序,this 是包含代码的页面,它试图演示 ALTER 有多么糟糕,但同时我不理解程序流程。

     PERFORM 2100-PROCESS-RECORD THRU 2199-EXIT.
...
 2100-PROCESS-RECORD. 
     GO TO 2110-PROCESS-HEADER.
*
 2110-PROCESS-HEADER.
* code to process a file header
     ALTER 2100-PROCESS-RECORD TO 2120-PROCESS-DETAIL.
     GO TO 2199-EXIT.
*
 2120-PROCESS-DETAIL.
* code to process a detail record 
     GO TO 2199-EXIT.
...
*
 2199-EXIT.
     EXIT.

在我看来,流程是这样的:

     PERFORM 2100-PROCESS-RECORD THRU 2199-EXIT.
...
 2100-PROCESS-RECORD. 
     GO TO 2110-PROCESS-HEADER.
*
 2110-PROCESS-HEADER.
* code to process a file header
     ALTER 2100-PROCESS-RECORD TO 2120-PROCESS-DETAIL.
     GO TO 2199-EXIT.

 2199-EXIT.
     EXIT.

如果 ALTER 是要更改 GO-TO 的目的地,那么如果 GO-TO 已经执行并且程序退出了,那么它还有什么用呢?

I came across a piece of cobol program which got me confused, this is the page containing the code, it try to demonstrate how bad ALTER is but at the same I don't understand the program flow.

     PERFORM 2100-PROCESS-RECORD THRU 2199-EXIT.
...
 2100-PROCESS-RECORD. 
     GO TO 2110-PROCESS-HEADER.
*
 2110-PROCESS-HEADER.
* code to process a file header
     ALTER 2100-PROCESS-RECORD TO 2120-PROCESS-DETAIL.
     GO TO 2199-EXIT.
*
 2120-PROCESS-DETAIL.
* code to process a detail record 
     GO TO 2199-EXIT.
...
*
 2199-EXIT.
     EXIT.

In my mind, the flow is like this:

     PERFORM 2100-PROCESS-RECORD THRU 2199-EXIT.
...
 2100-PROCESS-RECORD. 
     GO TO 2110-PROCESS-HEADER.
*
 2110-PROCESS-HEADER.
* code to process a file header
     ALTER 2100-PROCESS-RECORD TO 2120-PROCESS-DETAIL.
     GO TO 2199-EXIT.

 2199-EXIT.
     EXIT.

If ALTER is to change the destination of a GO-TO, how can it be useful if the GO-TO was already executed and the program exited?

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

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

发布评论

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

评论(1

静若繁花 2024-11-22 10:55:08

http://home.swbell.net/mck9/cobol/style/alter.html 对此进行了解释。您对于第一次执行是正确的,但是在后续运行中,行为发生了变化:

“我们第一次执行 PERFORM,控制权通过 2110-PROCESS-HEADER。但是,最后的 ALTER该段的内容更改了 2100-PROCESS-RECORD 中 GO TO 的目标,因此,在 PERFORM 的所有后续执行中,控制不会传递。 2110-PROCESS-HEADER。而是通过 2120-PROCESS-DETAIL。

“潜在的混乱是显而易见的。更改后的 GO TO 并没有到达它声称要去的地方——相反,它到达了某个远程代码段中指定的位置。要理解代码是如何工作的,你需要知道 ALTER 存在,并且需要知道执行 ALTER 的所有情况。”

这被称为自修改代码,并且很难理解和调试。对于一些简单的阅读睡前,我建议 http://www.pbm.com/~lindahl/mel.html< /a> 的Mel 的故事,

在 Cobol 中,EXIT 语句并不意味着“退出程序”:http://publib.boulder.ibm.com/infocenter/iadthelp/v6r0/index.jsp?topic=/com.ibm.etools.iseries.langref.doc/evfeb4ls124.htm

http://home.swbell.net/mck9/cobol/style/alter.html explains it. you're correct for the first execution, but on subsequent runs the behavior is changed:

"The first time we execute the PERFORM, control passes through 2110-PROCESS-HEADER. However, the ALTER at the end of that paragraph changes the destination of the GO TO in 2100-PROCESS-RECORD. As a result, on all subsequent executions of the PERFORM, control does not pass through 2110-PROCESS-HEADER. It passes through 2120-PROCESS-DETAIL instead.

"The potential for confusion is obvious. The altered GO TO does not go where it claims to go -- instead, it goes to a place specified in some remote piece of code. To understand how the code works you need to know that the ALTER is present, and you need to know all the circumstances which execute the ALTER."

it's called self-modifying code, and it's very hard to understand and debug. for some light reading before bed, I recommend http://www.pbm.com/~lindahl/mel.html the story of Mel.

in Cobol, the EXIT statement does not mean "exit the program": http://publib.boulder.ibm.com/infocenter/iadthelp/v6r0/index.jsp?topic=/com.ibm.etools.iseries.langref.doc/evfeb4ls124.htm

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