From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border2.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: A good program that not compile Date: Wed, 21 May 2014 14:49:30 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="f944b7aa56b4100b8770465c51f11294"; logging-data="7276"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18aX+8pzGYMunVYPA6v/+T6rKE6D0oW1Hc=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:iNnKF8KWnAZk+9LVEB8hx0lg7dA= sha1:IkH4cO84i0iw4L5A2d+b1dZdcFg= X-Original-Bytes: 2448 Xref: number.nntp.dca.giganews.com comp.lang.ada:186538 Date: 2014-05-21T14:49:30+01:00 List-Id: Victor Porton writes: > The following does not compile. For very good reasons. Obtain_Handle(File_Handle) ought to be a function! It should take an in parameter, not in out! I take it your point is that you want to be able to declare function Obtain_Handle(Object: Abstract_Handle) return Integer is abstract; but I find that (with the latest compilers) this works: function Obtain_Handle(Object: Abstract_Handle) return Integer is (raise Program_Error); with the slight disadvantage of postponing failure to run time (which might happen anyway with your proposal). with Ada.Finalization; package My is type Abstract_Handle is new Ada.Finalization.Limited_Controlled with record Handle: Integer; end record; function Obtain_Handle(Object: Abstract_Handle) return Integer is (raise Program_Error); overriding procedure Initialize(Object: in out Abstract_Handle); type File_Handle is new Abstract_Handle with null record; overriding function Obtain_Handle(Object: File_Handle) return Integer; end My; package body My is overriding procedure Initialize(Object: in out Abstract_Handle) is begin Object.Handle := Obtain_Handle(Abstract_Handle'Class (Object)); end; overriding function Obtain_Handle(Object: File_Handle) return Integer is begin return 123; -- Suppose 123 is a file handle, for an example end; end My;