RPG(LE) 中的条件编译

发布于 2024-08-02 03:22:28 字数 388 浏览 4 评论 0原文

我是否可以根据程序中是否定义了变量来包含一段代码,或者预处理器完全无法访问此信息,只能访问编译条件? 即我正在寻找类似的东西:

/IF DEFINED(myVariable)
D myOtherVariable       S                  like(myVariable)
/ELSE
D myOtherVariable       S             20A
/ENDIF

这个 link似乎表明这是不可能的。 如果是这样,有人知道另一种方法来实现这一目标吗?

Can I include a section of code based on whether a variable is defined in my program, or is the preprocessor completely unable to access this information, only compilation conditions? I.e. I'm after something like:

/IF DEFINED(myVariable)
D myOtherVariable       S                  like(myVariable)
/ELSE
D myOtherVariable       S             20A
/ENDIF

This link appear to suggest it is not possible. If so does anyone know of another way to achieve this?

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

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

发布评论

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

评论(2

じее 2024-08-09 03:22:28

如果有的话,这将是一个很好的功能,但不幸的是,今天它已经不能这样工作了。 DEFINED 后面括号中的值必须是定义的条件名称,而不是变量名称。 使其发挥作用的方法是,每当您在任何程序或副本中定义特定变量时,都使用 /DEFINE 指令。 这是否是推荐的做法,完全取决于这些情况的使用情况。

您问题中提供的链接是正确的,我同意结论。

It would be a nice feature to have, but unfortunately, it doesn't work that way today. The value in parenthesis after DEFINED must be a defined condition name, not a variable name. The way to make it work is to have a /DEFINE directive whenever you define that specific variable in any of programs or copybooks. It all depends on usage for these situations as far as whether or not this is a recommended practice.

The link provided in your question is spot-on and I agree with the conclusions.

<逆流佳人身旁 2024-08-09 03:22:28

作为附加提示,请使用有关此主题的 C 编程书籍,而不是 IBM RPGLE 书籍。 IBM 书籍描述了指令可以做什么。 C 书籍描述了如何在现实世界的程序(例如Linux 开源程序)中使用它。 遵循这种风格可以让其他程序员更容易阅读你的 RPG 源代码。

As an additional hint, use C programming books for this subject, not the IBM RPGLE books. The IBM books describe what can be done with directives. The C books describe how it is used in real world programs (e.g. Linux open source programs). Following that style makes your RPG sources much more readable for other programmers.

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