🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fr.comp.lang.ada
Article #20

Re: Renommage

#20
From: slos
Date: Sun, 26 Aug 2012 20:49
137 lines
5260 bytes
Bonjour Monsieur Carbonne,

Merci pour votre réponse.

Si je ne m'abuse, nous vous devons aussi CairoAda non ?

Vous dites ne pas avoir fait de Ada depuis longtemps.
Pourriez vous dire pourquoi ?

J'ai donc révisé mon Ada 2005 de J. Barnes et cela a confirmé vos dires : cf. p. 226 et suivantes.

D'où :

-- Ada For Automation
with Interfaces;
package A4A is

   type Byte is new Interfaces.Unsigned_8;
   --  8-bit unsigned integer

   type Word is new Interfaces.Unsigned_16;
   -- 16-bit unsigned integer

   type DWord is new Interfaces.Unsigned_32;
   -- 32-bit unsigned integer

    function SHL
     (Value  : DWord;
      Amount : Natural) return DWord renames Shift_Left;
   -- Shift Left

   function ROL
     (Value  : DWord;
      Amount : Natural) return DWord renames Rotate_Left;
   -- Rotate Left

   -- Global variables

   Quit : Boolean := False;
   -- When Quit is set, the application shall exit
   -- Quit is set either by SIGINT Handler or by GUI
   -- All tasks should care about Quit and terminate themselves

end A4A;

Et pour tester la chose :

with Ada.Text_IO;
with Ada.Integer_Text_IO;
with Ada.Long_Integer_Text_IO;

with A4A; use A4A;

procedure Test_Shift is
   MyDWord  : A4A.DWord;
   MyDWord1 : A4A.DWord;
   MyDWord2 : A4A.DWord;
   --MyWord : A4A.Word;
   --MyByte : A4A.Byte;
begin
   MyDWord := 16#12345678#;
   Ada.Text_IO.Put (Item => "MyDWord : ");
   Ada.Long_Integer_Text_IO.Put (Item => Long_Integer(MyDWord), Base => 16);
   Ada.Text_IO.New_Line(2);

   Ada.Text_IO.Put_Line (Item => " -- " & "SHL (Value => MyDWord, Amount => 4);");
   MyDWord := A4A.SHL (Value => MyDWord, Amount => 4);
--     MyDWord := A4A.Shift_Left (Value => MyDWord, Amount => 4);

   Ada.Text_IO.Put (Item => "MyDWord : ");
   Ada.Long_Integer_Text_IO.Put (Item => Long_Integer(MyDWord), Base => 16);
   Ada.Text_IO.New_Line(2);

   Ada.Text_IO.Put_Line (Item => " -- " & "ROL (Value => MyDWord, Amount => 4);");
   MyDWord := A4A.ROL (Value => MyDWord, Amount => 4);
--     MyDWord := A4A.Rotate_Left (Value => MyDWord, Amount => 4);

   Ada.Text_IO.Put (Item => "MyDWord : ");
   Ada.Long_Integer_Text_IO.Put (Item => Long_Integer(MyDWord), Base => 16);
   Ada.Text_IO.New_Line(2);


end Test_Shift;



Le dimanche 26 août 2012 17:07:34 UTC+2, Damien Carbonne a écrit :

    Bonjour,

    Cela fait longtemps que je n'ai pas fait d'Ada mais, pour �viter
    d'�crire "with Interfaces" l� o� tu �cris "with A4A", une solution
    consisterait, si je me souviens bien, � remplacer les d�clarations
    "subtype XXX is Interfaces.YYY;" par "type XXX is new is Interfaces.YYY;".

    Avec "subtype XXX", on ne fait que d�clarer une sorte d'alias de YYY.
    Les fonctions primitives du type XXX sont en fait celles de YYY, qui
    sont (toujours) dans le package Interfaces, qui doit donc �tre import�.

    En revanche, avec "type XXX", on cr�e un nouveau type (XXX), qui ram�ne
    avec lui les fonctions primitives de YYY dans le package A4A. Il n'y a
    donc pas besoin de de faire "with Interfaces".

    Les sp�cialistes Ada utiliseront un vocabulaire plus pr�cis et exact que
    le mien, mais j'esp�re que ces explications sont compr�hensibles pour toi.

    Donc je pense qu'il te suffis d'�crire  ceci :

    -- Ada For Automation
    with Interfaces;
    package A4A is

         type Byte is new Interfaces.Unsigned_8;
         --  8-bit unsigned integer

         type Word is new Interfaces.Unsigned_16;
         -- 16-bit unsigned integer
         ...


    Cordialement,
    Damien Carbonne
Technical Details
Message-ID: <0bd62ab6-9ba5-4656-a951-a1d0636d0140@googlegroups.com>
Path: arc1-ca.pugleaf.net!a5ni15572pbv.0!nntp.google.com!news2.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
References: <1eca5845-9df8-4b81-b6e9-da09628761ec@googlegroups.com> <503A3BB6.5040000@free.fr>

Show Full Headers
Complete Article Headers
X-Google-Thread: 107e1d,5c0f9e92502143f6
X-Google-NewGroupId: yes
X-Google-Attributes: gid43d0c745c,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII
Received: by 10.66.89.162 with SMTP id bp2mr1758225pab.4.1346014189411;
        Sun, 26 Aug 2012 13:49:49 -0700 (PDT)
Path: arc1-ca.pugleaf.net!a5ni15572pbv.0!nntp.google.com!news2.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From: slos <new.stephane.los@gmail.com>
Newsgroups: fr.comp.lang.ada
Subject: Re: Renommage
Date: Sun, 26 Aug 2012 13:49:49 -0700 (PDT)
Organization: http://groups.google.com
Lines: 139
Message-ID: <0bd62ab6-9ba5-4656-a951-a1d0636d0140@googlegroups.com>
References: <1eca5845-9df8-4b81-b6e9-da09628761ec@googlegroups.com> <503A3BB6.5040000@free.fr>
NNTP-Posting-Host: 84.103.80.19
Mime-Version: 1.0
X-Trace: posting.google.com 1346014189 5359 127.0.0.1 (26 Aug 2012 20:49:49 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 26 Aug 2012 20:49:49 +0000 (UTC)
Cc: slos <new.stephane.los@gmail.com>
In-Reply-To: <503A3BB6.5040000@free.fr>
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=84.103.80.19; posting-account=O3LyFwoAAACc1uh60ZcOUmAGdDmGsEcV
User-Agent: G2/1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable