问题
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 !
回答1:
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
回答2:
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;
回答3:
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).
回答4:
Yep, I see this one used often to shut the compiler up about unreferenced variables in a procedure:
pragma Unreferenced(Variable);
来源:https://stackoverflow.com/questions/2333742/use-of-pragmas-in-ada