在 Ada 中使用 Pragma

发布于 2024-08-22 17:48:46 字数 87 浏览 8 评论 0原文

谁能给我提供一些简单的工作示例来说明 Ada 2005 中编译指示的使用?我知道编译指示用于优先级流程,只是我还没有遇到过工作示例!

非常感谢!

Can anyone supply me with simple working examples which illustrate the use of pragmas in Ada 2005 ? I understand that pragmas are used to priorities processes, just that I have not come across working examples !

Much appreciated !

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

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

发布评论

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

评论(4

简单气质女生网名 2024-08-29 17:48:46

Ada pragma 是一种语言功能,允许调整或微调 Ada 程序的行为。 Ada 语言标准定义了许多编译指示,但编译器供应商也可以定义自己的编译指示。

编译指示的主题涵盖的不仅仅是流程[任务]优先级,这里有一个列表需要检查的标准和供应商提供的编译指示。

您究竟想借助实用程序做什么?设定任务优先级?

-- Not compile checked:
with System; use System;

task Prioritized_Task is
   pragma Priority(System.Default_Priority + 1);

   entry Start;

end Prioritized_Task;

An Ada pragma is a language feature that allows adjusting or fine-tuning the behavior of an Ada program. A number of pragmas are defined by the Ada language standard, but compiler vendors can also define their own.

The subject of pragmas cover far more than just process [tasking] priorities, here's a list of standard and vendor-provided pragmas to check out.

What exactly are you trying to do with the aid of pragmas? Set task priorities?

-- Not compile checked:
with System; use System;

task Prioritized_Task is
   pragma Priority(System.Default_Priority + 1);

   entry Start;

end Prioritized_Task;
终止放荡 2024-08-29 17:48:46

与 Ada 的大部分内容一样,我认为这里最好的答案实际上是咨询LRM管理任务优先级的部分实际上非常可读,无论如何,对于语言标准定义。

请注意,您还可以在运行时设置任务的优先级< /a> 不使用编译指示。这利用了Ada.Dynamic_Priorities包。这就是我现在通常做的事情,除非出于某种奇怪的原因在编译时就知道所需的优先级,并且我不介意对其进行硬编码。

我强烈建议像您这样的高级用户浏览一下 LRM,看看所有语言都为您提供了什么。请特别注意附件(以字母开头的部分),因为这是记录大多数好东西的地方。就您而言,您可能会对实时附件(附件 D)特别感兴趣。

As with much of Ada, I think the best answer here is really to consult the LRM. The section on managing task priorities is actually very readable, for a language standard definition anyway.

Note that you can also set the priority of a task at runtime without use of a pragma. This makes use of the package Ada.Dynamic_Priorities. This is what I typically do these days, unless for some weird reason the desired priority is known at compile time, and I don't mind hard-coding it.

I highly suggest that advanced users such as yourself poke through the LRM to see what all the language provides you. Pay particular attention to the annexes (the sections starting with a letter), as that is where most of the good stuff is documented. In your case, you will probably be particularly interested in the Real-Time annex (Annex D).

○愚か者の日 2024-08-29 17:48:46

搜索comp.lang.ada 有关优先级<的最新讨论/code>有几个有趣的例子。 这个似乎特别适合您的问题。

附录:另外两个示例性来源是 Ada 95 的基本原理Ada 2005 的基本原理

A search of comp.lang.ada for recent discussions about priorities has several interesting examples. This one seems particularly apropos to your question.

Addendum: Two other exemplary sources are the Rationale for Ada 95 and Rationale for Ada 2005

成熟的代价 2024-08-29 17:48:46

是的,我看到这个经常用来让编译器关闭过程中未引用的变量:

pragma Unreferenced(Variable);

Yep, I see this one used often to shut the compiler up about unreferenced variables in a procedure:

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