Deutsch   English   Français   Italiano  
<uco7u8$156$1@shakotay.alphanet.ch>

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

Path: ...!newsreader4.netcologne.de!news.netcologne.de!news.imp.ch!news.alphanet.ch!alphanet.ch!.POSTED!not-for-mail
From: DrPi <314@drpi.fr>
Newsgroups: fr.comp.lang.ada
Subject: =?UTF-8?B?UmU6IFF1ZXN0aW9uIGRlIGfDqW7DqXJpY2l0w6k=?=
Date: Wed, 30 Aug 2023 22:13:57 +0200
Organization: Posted through news.alphanet.ch
Message-ID: <uco7u8$156$1@shakotay.alphanet.ch>
References: <uclnsh$fii$1@shakotay.alphanet.ch>
 <c3d74ebf-7153-4eb2-a22d-72b7c77ecf0bn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 30 Aug 2023 20:14:00 -0000 (UTC)
Injection-Info: shakotay.alphanet.ch; posting-account="dr.pi";
	logging-data="1190"; mail-complaints-to="usenet@alphanet.ch"; posting-host="bda8ab3c43e8ad8cb626bfebe8390999.nnrp.alphanet.ch"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha256:nZmtZ0cIbpwnaPeVQMCsMFAMkBO5qN6AsJ0tpuzKFFI=
In-Reply-To: <c3d74ebf-7153-4eb2-a22d-72b7c77ecf0bn@googlegroups.com>
Content-Language: fr
Bytes: 3144
Lines: 55

> --  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;
> 

Je ne comprends pas "nul : Item_Type" dans les paramètres génériques. A 
quoi sert cette ligne ?

Je ne comprends pas non plus pourquoi on passe "Item_Type" et 
"Index_Type" sachant que "Array_Type" définit complètement le type 
("char_array" ici).

Dans mon cas, je veux passer un type entièrement contraint en générique. 
La taille du tableau de sortie doit être égale au type entièrement 
contraint passé en générique, pas au paramètre "Item" de la fonction.
Comment faire ?

Sinon, il faudrait avoir accès à l'élément assigné (LHS) à partir de la 
fonction.
En VHDL-2019 (langage très fortement inspiré de Ada), une fonction peut 
s'écrire :
function my_func (param1 : in t_type1; param2 : in t_type2) return 
param_ret of t_type_ret;

Par exemple avec "var := my_func (var1, var2);"
la fonction "my_func" a accès à "var" à travers l'identifiant 
"param_ret". Dans "my_func", il est possible d'utiliser 
"param_ret'Length" ou "param_ret'Range" par exemple.
Je ne crois pas que ce soit possible en Ada. Exact ?