Ada 95 Quality and Style Guide Chapter 7

Chapter 7: Portability - TOC - 7.1 FUNDAMENTALS

7.1.9 Arbitrary Order Dependencies

guideline

  • Avoid depending on the order in which certain constructs in Ada are evaluated.

  • example

    The output of this program depends upon the order of evaluation of subprogram parameters, but the Ada Reference Manual (1995, 6.4) specifies that these evaluations are done in an arbitrary order:

    package Utilities is
       function Unique_ID return Integer;
    end Utilities;
    
    package body Utilities is
    
       ID : Integer := 0;
    
       function Unique_ID return Integer is
       begin
          ID := ID + 1;
          return ID;
       end Unique_ID;
    
    end Utilities;
    
    --------------------------------------------------------------------------------
    with Ada.Text_IO;
    with Utilities; use Utilities;
    procedure P is
    begin
       Ada.Text_IO.Put_Line (Integer'Image(Unique_ID) & Integer'Image(Unique_ID));
    end P;
    
    

    If the parameters to the "&" function are evaluated in textual order, the output is:

    1 2

    If the parameters are evaluated in the reverse order, the output is:

    2 1

    rationale

    The Ada language defines certain evaluations to occur in arbitrary order (e.g., subprogram parameters). While a dependency on the order of evaluation may not adversely affect the program on a certain implementation, the code might not execute correctly when it is ported. For example, if two actual parameters of a subprogram call have side effects, the effect of the program could depend on the order of evaluation (Ada Reference Manual 1995, 1.1.4). Avoid arbitrary order dependencies, but also recognize that even an unintentional error of this kind could prohibit portability.


    < Previous Page Search Contents Index Next Page >
    1 2 3 4 5 6 7 8 9 10 11
    TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC
    Appendix References Bibliography