How to stop execution in my program

后端 未结 2 1527
有刺的猬
有刺的猬 2020-12-21 02:10

Without copy-pasting my code here, how can I stop my ADA program from executing anymore lines of code during run-time if it calculates a certain value to \'X\'?

some

2条回答
  •  执念已碎
    2020-12-21 02:16

    There isn’t any specific syntax for this.

    If you are in the main procedure, a simple return will do.

    An Ada83-compatible answer is here on SO.

    Both those are OK so long as you don’t have any tasks.

    There’s an Ada95 Rosetta Code solution, which will work whether you have tasks or not:

    with Ada.Task_Identification;  use Ada.Task_Identification;
    
    procedure Main is
       -- Create as many task objects as your program needs
    begin
       -- whatever logic is required in your Main procedure
       if some_condition then
          Abort_Task (Current_Task);
       end if;
    end Main;
    

    and a GNAT-specific solution, also OK with tasks:

    with Ada.Text_IO; use Ada.Text_IO;
    with GNAT.OS_Lib;
    procedure Stopping is
       procedure P is
       begin
          GNAT.OS_Lib.OS_Exit (0);
       end P;
    begin
       Put_Line ("starting");
       P;
       Put_Line ("shouldn't have got here");
    end Stopping;
    

提交回复
热议问题