Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You really keep moving the goalposts. Your new additions are, in a word, terrible: they don't compile at all and they are a smattering of obviously cut-and-pasted code as evidenced by mismatching function-names (e.g. <code>Int_Is_Valid</code>/<code>Pair_Is_Valid</code>).</p> <p>First, let's use a signature-package.</p> <p><code>signature.ads</code> </p> <pre><code>generic Type Item is private; Default : in Item; package SIGNATURE is end SIGNATURE; </code></pre> <p><code>foo.ads</code></p> <pre><code>with System, SIGNATURE; generic with package Item_Pkg is new SIGNATURE(&lt;&gt;); Addr : System.Address; with function Is_Valid(X : Item_Pkg.Item) return Boolean is &lt;&gt;; package Foo is use Item_Pkg; function Read_Eeprom return Item; function Is_Valid (Data_Ptr : access Item) return Boolean; private Port : Item; pragma Volatile( Port ); Pragma Import( Convention =&gt; Ada, Entity =&gt; Port ); For Port'Address Use Addr; end Foo; </code></pre> <p><code>foo.adb</code></p> <pre><code>package body Foo is function Read_Eeprom return Item is Result : constant Item:= Port; begin if Is_Valid(Result) then return Result; else return Default; end if; end Read_Eeprom; function Is_Valid (Data_Ptr : access Item) return Boolean is begin return Is_Valid(Data_Ptr.all); end Is_Valid; end Foo; </code></pre> <p><code>driver.ads</code></p> <pre><code>package Driver is MAX_INT : constant Integer := 100; MIN_INT : constant Integer := 0; -- Special / Non-Scaler Type type Pair_Type is record X : Integer; Y : Integer; end record; -- Is Valid **USING OVERLOADS** function Is_Valid(Int : Integer ) return Boolean; function Is_Valid(Pair : Pair_Type) return Boolean; My_Int : Integer; My_Pair : Pair_Type; private Default_Pair : constant Pair_Type := (0,0); Default_Integer : constant Integer := 0; end Driver; </code></pre> <p><code>driver.adb</code></p> <pre><code>with Foo, SIGNATURE; package body Driver is -- Is Valid function Is_Valid(Int : Integer) return Boolean is (Int &lt;= MAX_INT and Int &gt;= MIN_INT); function Is_Valid(Pair : Pair_Type) return Boolean is (Pair.X'Valid and Pair.Y'Valid); package Int_pkg is new SIGNATURE(Integer, 0); package Pair_Pkg is new SIGNATURE(Pair_Type, Default_Pair); -- Using defaults for Is_Valid. package Int_Obj is new Foo (Item_Pkg =&gt; Int_Pkg, Addr =&gt; My_Int'Address ); package Pair_Obj is new Foo(Item_Pkg =&gt; Pair_Pkg, Addr =&gt; My_Pair'Address ); end Driver; </code></pre> <hr> <p>Given the rather obvious structuring of your code around <code>access</code>-types, I'm guessing that you are trying to "import" knowledge from C or C++. That's going to cause you a lot of trouble/work later on if you try using Ada like it's a C-style language.</p> <p>Also, it may be beneficial to sit down, take a breath, and think about things <a href="http://blog.kickin-the-darkness.com/2007/08/fundamental-theory-of-ada.html" rel="nofollow">in terms of types</a> both the problem-space and, separately, the architecture.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload