Deutsch   English   Français   Italiano  
<a36a4183-5817-4efa-86ee-09e4d883bb23n@googlegroups.com>

View for Bookmarking (what is this?)
Look up another Usenet article

X-Received: by 2002:a05:6214:7e6:b0:64f:92d1:4871 with SMTP id bp6-20020a05621407e600b0064f92d14871mr84881qvb.6.1693593760663;
        Fri, 01 Sep 2023 11:42:40 -0700 (PDT)
X-Received: by 2002:a05:6a00:2d2a:b0:68c:460b:88f8 with SMTP id
 fa42-20020a056a002d2a00b0068c460b88f8mr1394784pfb.1.1693593760412; Fri, 01
 Sep 2023 11:42:40 -0700 (PDT)
Path: ...!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: fr.comp.lang.ada
Date: Fri, 1 Sep 2023 11:42:39 -0700 (PDT)
In-Reply-To: <ucstqi$vg1$1@shakotay.alphanet.ch>
Injection-Info: google-groups.googlegroups.com; posting-host=2a02:1210:2e90:8100:440c:560e:623c:f363;
 posting-account=gRqrnQkAAAAC_02ynnhqGk1VRQlve6ZG
NNTP-Posting-Host: 2a02:1210:2e90:8100:440c:560e:623c:f363
References: <uclnsh$fii$1@shakotay.alphanet.ch> <c3d74ebf-7153-4eb2-a22d-72b7c77ecf0bn@googlegroups.com>
 <uco7u8$156$1@shakotay.alphanet.ch> <26366041-5cd3-4ccf-b1ac-a937a1c53f3en@googlegroups.com>
 <ucql7j$vn3$1@shakotay.alphanet.ch> <a98095df-01d5-45ef-8bd3-ac2968e0a344n@googlegroups.com>
 <ucstqi$vg1$1@shakotay.alphanet.ch>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a36a4183-5817-4efa-86ee-09e4d883bb23n@googlegroups.com>
Subject: =?UTF-8?B?UmU6IFF1ZXN0aW9uIGRlIGfDqW7DqXJpY2l0w6k=?=
From: Gautier write-only address <gautier_niouzes@hotmail.com>
Injection-Date: Fri, 01 Sep 2023 18:42:40 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Bytes: 3155
Lines: 50

Que dis-tu du code ci-dessous?
Une question =C3=A0 mon tour: pourquoi le choix 32, 64, 128 (puissances de =
deux) puis 255 (=3D2^8 - 1) et pourquoi +2 pour la longueur des trois premi=
ers tableaux et +1 pour le dernier?

----8<-----------8<-----------8<-----------8<-----------8<-----------8<----=
---
with Interfaces.C;

procedure genconv is

  generic
  type Item_Type is private;
  terminator : Item_Type;
  type Index_Type is mod <>;
  array_length : Index_Type;
  type Array_Type is array (Index_Type range <>) of Item_Type;
  with function To_Item_Type (c : Character) return Item_Type;

  package TW_Factory is
    subtype Tailored_Array is Array_Type (Index_Type'(1) .. array_length);
    function To_TW_STR (message : String) return Tailored_Array;
  end TW_Factory;

  package body TW_Factory is
    function To_TW_STR (message : String) return Tailored_Array is
    begin
      pragma Assert (message'Length =3D array_length);  --  Or adjust termi=
nator position ?
      return Result : Tailored_Array with Relaxed_Initialization do
        for J in message'Range loop
          Result (Index_Type (J - message'First + 1)) :=3D To_Item_Type (me=
ssage (J));
        end loop;
        Result (Index_Type (message'Length + 1)) :=3D terminator;
      end return;
    end To_TW_STR;
  end TW_Factory;

  use Interfaces.C;

  type char_array is array (size_t range <>) of aliased char;

  package TW_128 is new TW_Factory (char, nul, size_t, 128, char_array, to_=
C);

  x : TW_128.Tailored_Array;

begin
  x :=3D TW_128.To_TW_STR ("Hey!");
end;