COBOL 的范围是什么

发布于 2024-10-18 14:03:01 字数 32 浏览 4 评论 0原文

COBOL 的范围是如何定义的?它是静态范围的吗?

How is COBOL's scope defined? Is it statically scoped?

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

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

发布评论

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

评论(3

醉殇 2024-10-25 14:03:01

Cobol 具有变量的编译时绑定,有时称为静态作用域。

其中,Cobol 支持程序内的多个作用域层:

  • “外部”变量相当于 Fortran 或汇编程序公共部分,它们是真正的全局变量。

  • 在工作存储中声明为全局的“全局程序范围”变量对于声明它们的整个程序以及该程序中包含的所有嵌套子程序都是可见的。

  • 在工作存储中声明的“程序范围”变量对于声明它们的整个程序可见。

  • 在本地存储中声明的“程序范围”变量对于声明它们的整个程序都是可见的,但会在每次调用时删除并重新初始化。想想线程作用域,有点。

  • “嵌套程序作用域” Cobol 不区分程序和函数/过程,过程或函数的等价物称为程序。一个程序中可以包含无限多个程序,并且每个程序的变量仅在该单个程序的范围内可见。您可以将其视为函数/过程范围。

许多供应商拥有的 OO 扩展以及 2002 年标准定义了传统的公共/受保护/私有对象范围和方法范围。

“Cobol”与雷达、激光和水肺一样古老,我们可以停止缩写它吗?

Cobol has compile time binding for variables, sometimes called static scope.

Within that, Cobol supports several layers of scope within programs:

  • "External" variables are the equivilent of a Fortran or assembler common section, they are truly global.

  • "Global Program Scope" variables declared in working storage as global are visible to the entire program in which they are declared AND in all nested subprograms contained in that program.

  • "Program Scope" variables declared in working storage are visible to the entire program in which they are declared.

  • "Program Scope" variables declared in local storage are visible to the entire program in which they are declared, but are deleted and reinitialized on every invocation. Think thread scoped, sorta.

  • "Nested Program Scope" Cobol does not distinguish between programs and functions/procedures, its equvilent of a procedure or function is called a program. An infinite number of programs can be contained within a program, and the variables of each are visible only within the scope of that individual program. You could think of this as function/procedure scope.

The OO extensions that many vendors have, and the 2002 standard, defines the traditional public/protected/private object scope and method scope.

"Cobol" is as old as Radar, Laser, and Scuba, can we please stop acronymizing it?

蛮可爱 2024-10-25 14:03:01

COBOL 程序中的所有变量都是全局范围的。事实上,不存在“范围”(在传统的 COBOL 中,我不会搞乱 OO 扩展),而只是“模块”或“程序”。

模块间通信是通过链接部分(通常通过 ref 传递)完成的,并且所有变量对于被调用的模块都是可见的。

All variables in a COBOL program are globally scoped. In fact, there are no "scopes" (in traditional COBOL, I'm not messing with OO extensions), but just "modules" or "programs".

Intermodule communication is done via the Linkage Section (usually passed by ref), and also all variables there are visible from the called module.

人间不值得 2024-10-25 14:03:01

COBOL 使用静态(词法)作用域(C、C++、Java 和 Pascal 也是如此)。动态作用域在编程世界中并不常见。我认为 Lisp 和 SNOBOL 的某些版本使用了动态作用域。

如果您有兴趣了解编程语言的范围,您应该查看 本文档

COBOL uses static (lexical) scope (as do C, C++, Java and Pascal). Dynamic scope is not all that common in the programming world. I think some versions of Lisp and SNOBOL used dynamic scope.

If you are interested in understanding scope with respect to programming languages you should review this document

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