From mboxrd@z Thu Jan 1 00:00:00 1970
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Blady
Newsgroups: comp.lang.ada
Subject: Renaming primitives.
Date: Wed, 10 Jan 2024 11:37:39 +0100
Organization: A noiseless patient Spider
Message-ID:
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 10 Jan 2024 10:37:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5a50a221da06eb55dc22adad43acb4c5";
logging-data="2589657"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1CaNwJmpAI7xj8dRokrnH"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:adKmvt+rHAxOG62ahq6RXnipnb8=
Content-Language: fr, en-US
Xref: news.eternal-september.org comp.lang.ada:65977
List-Id:
Hello,
Is a procedure renaming equivalent to a simple call?
For instance:
procedure Log (Msg : String) is
begin
Ada.Text_IO.Put_Line (Msg);
end Log;
procedure My_Log_1 (Msg : String) is
begin
Log (Msg);
end My_Log_1;
procedure My_Log_2 (Msg : String) renames Log;
Almost, My_Log_1 is equivalent to My_Log_2, isn't it?
Is it the same with primitives?
For instance:
package Loggings is
type Logging is tagged record
Output : Ada.Text_IO.File_Access;
end record;
procedure Log (Handler : Logging; Msg : String);
end Loggings;
My_Handler : aliased Loggings.Logging := (Output =>
Ada.Text_IO.Current_Output);
My_Generic_Handler : access Loggings.Logging'Class := My_Handler'Access;
procedure My_Log_3 (Msg : String) renames My_Generic_Handler.Log;
To my surprise (well I hoped) My_Log_3 is compiled by GNAT.
Is it conformed to the Ada standard?
What is happening if My_Generic_Handler change?
For instance:
type Full_Logging is new Logging with null record;
procedure Log (Handler : Full_Logging; Msg : String);
...
My_Full_Handler : aliased Loggings.Full_Logging := (Output =>
Ada.Text_IO.Current_Output);
...
My_Generic_Handler := My_Full_Handler'Access;
Well, logically (?), My_Log_3 follows the change and outputs with
Full_Logging.
Unfortunately, GNAT claims renaming with several parameters.
I add:
procedure Log (Handler : Logging; Msg : String; Err : Natural);
...
procedure My_Log_4 (Msg : String; Err : Natural) renames
My_Generic_Handler.Log;
I got:
test_20240110_renproc.adb:47:14: error: too many arguments in call to "log"
Is it a correct or a GNAT issue?
Full source code on demand.
Thanks.
Happy New Year to all!
Pascal.