From: Victor Porton <porton@narod.ru>
Subject: Re: Need a way to convert a constant to a variable
Date: Sat, 05 Aug 2017 19:25:29 +0300
Date: 2017-08-05T19:25:29+03:00 [thread overview]
Message-ID: <om4ri3$1se8$1@gioia.aioe.org> (raw)
In-Reply-To: om4onb$evc$1@dont-email.me
Jeffrey R. Carter wrote:
> On 08/05/2017 03:41 PM, Victor Porton wrote:
>>
>> Write a function with an "in" indefinite holder with a string, return
>> chars_ptr corresponding to the string.
>
> Your requirements are for an indefinite holder with a string, but your
> attempted solution is for an indefinite holder with a char_array. I will
> assume you meant an indefinite holder with a char_array.
Yes, my typo. I am about an indefinite holder with a char_array.
>> It looks like there is no solution of this in Ada 2012 :-(
>
> with Ada.Containers.Indefinite_Holders;
> with Interfaces.C.Strings;
>
> package Conv is
> package C_Str_Holders is new Ada.Containers.Indefinite_Holders
> (Element_Type => Interfaces.C.Char_Array, "=" => Interfaces.C."=");
>
> function To_Chars_Ptr (Item : C_Str_Holders.Holder)
> return Interfaces.C.Strings.Chars_Ptr is
> (Interfaces.C.Strings.New_Char_Array (Item.Element) );
> end Conv;
>
> This compiles fine, so clearly there is a way to do this without a
> language change.
Your code allocates a new string which requires to be freed later.
I want a function, which would return a pointer to the (not necessarily nul-
terminated) string hold in the indefinite holder, so that deallocation would
be not required and code would be more efficient (not requiring to copy the
char_array).
--
Victor Porton - http://portonvictor.org
next prev parent reply other threads:[~2017-08-05 16:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-05 13:41 Need a way to convert a constant to a variable Victor Porton
2017-08-05 14:48 ` Dmitry A. Kazakov
2017-08-05 15:11 ` Victor Porton
2017-08-05 16:44 ` Dmitry A. Kazakov
2017-08-05 17:45 ` Victor Porton
2017-08-05 19:37 ` Dmitry A. Kazakov
2017-08-05 15:41 ` Jeffrey R. Carter
2017-08-05 16:25 ` Victor Porton [this message]
2017-08-05 20:12 ` Jeffrey R. Carter
2017-08-05 17:59 ` Per Sandberg
2017-08-15 20:05 ` Eryndlia Mavourneen
2017-08-15 20:07 ` Eryndlia Mavourneen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox