Re: Question de généricité

Liste des GroupesRevenir à fcl ada 
Sujet : Re: Question de généricité
De : gautier_niouzes (at) *nospam* hotmail.com (Gautier write-only address)
Groupes : fr.comp.lang.ada
Date : 30. Aug 2023, 03:16:03
Autres entêtes
Message-ID : <c3d74ebf-7153-4eb2-a22d-72b7c77ecf0bn@googlegroups.com>
References : 1
User-Agent : G2/1.0
J'ai ajouté qqes paramètres formels:
with Interfaces.C;

procedure genconv is

use Interfaces.C;

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

--  subtype t_TW_STR32 is char_array (1 .. 34);
--  subtype t_TW_STR64 is char_array (1 .. 66);
--  subtype t_TW_STR128 is char_array (1 .. 130);
--  subtype t_TW_STR255 is char_array (1 .. 256);

generic
type Item_Type is private;
nul : Item_Type;
type Index_Type is mod <>;
type Array_Type is array (Index_Type range <>) of Item_Type;
with function To_Item_Type (c : Character) return Item_Type;
function To_TW_STR (Item : String) return Array_Type;

function To_TW_STR (Item : String) return Array_Type is
begin
return Result : Array_Type (1 .. Item'Length + 1) with Relaxed_Initialization do
for J in Item'Range loop
Result (Index_Type (J - Item'First + 1)) := To_Item_Type (Item (J));  --  Was J - Item'First
end loop;
Result (Index_Type (Item'Length + 1)) := nul;  --  Was Item'Last + 1
end return;
end To_TW_STR;

function To_TW_C is new To_TW_STR (char, nul, size_t, char_array, to_C);

begin
null;
end;

Variante: l'indexation de ton résultat commence par 0:
...
return Result : Array_Type (0 .. Item'Length) with Relaxed_Initialization do
for J in Item'Range loop
Result (Index_Type (J - Item'First)) := To_Item_Type (Item (J));
end loop;
Result (Index_Type (Item'Length)) := nul;
end return;

Date Sujet#  Auteur
29 Aug 23 * Question de généricité14DrPi
30 Aug 23 `* Re: Question de généricité13Gautier write-only address
30 Aug 23  `* Re: Question de généricité12DrPi
30 Aug 23   `* Re: Question de généricité11Gautier write-only address
31 Aug 23    `* Re: Question de généricité10DrPi
1 Sep 23     `* Re: Question de généricité9Gautier write-only address
1 Sep 23      `* Re: Question de généricité8DrPi
1 Sep 23       +* Re: Question de généricité3Gautier write-only address
2 Sep 23       i`* Re: Question de généricité2DrPi
2 Sep 23       i `- Re: Question de généricité1DrPi
2 Sep 23       `* Re: Question de généricité4J-P. Rosen
2 Sep 23        `* Re: Question de généricité3DrPi
15 Sep 23         `* Re: Question de généricité2Thomas
16 Sep 23          `- Re: Question de généricité1DrPi

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal