Ada Programming/Pragmas/No Return

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Ada. Time-tested, safe and secure.
Ada. Time-tested, safe and secure.
pragma No_Return (local_name);

Description[edit | edit source]

No Return is a representation pragma for procedures, which states that a procedure will never return normally; that is, it will raise an exception, loop endlessly, or terminate the program (e.g. by means of an imported function like C’s exit or by triggering a hardware reset).

On the call site, this enables detection of dead code and suppression of warnings about missing return statements or missing assignment to variables.

The compiler ensures that a non-returning procedure will indeed not return by raising Program_Error if it would otherwise.

Example[edit | edit source]

procedure P ( … );
pragma No_Return (P);
procedure Q (x: out … ) is
begin
  if Cond
  then P ( … );
    Some_Thing_Else; -- This is dead code--and due to No_Return probably a compiler warning!
  else x := … ;
  end if;
  -- No warning about a missing assignment to x here
end Q;

Portability[edit | edit source]

The pragma No_Return is standard in the language since Ada 2005. Some compilers (e.g. GNAT and AdaMagic) already recognised No_Return as implementation defined pragma before.[1]

See also[edit | edit source]

Wikibook[edit | edit source]

Ada Reference Manual[edit | edit source]

References[edit | edit source]

  1. AI95-00329 in Appendix: From: Tucker Taft, Sent: Tuesday, March 4, 2003 11:13 AM