* Troubles with C strings
@ 2014-07-26 14:13 Victor Porton
2014-07-26 15:15 ` Shark8
2014-07-26 18:41 ` Niklas Holsti
0 siblings, 2 replies; 8+ messages in thread
From: Victor Porton @ 2014-07-26 14:13 UTC (permalink / raw)
RM2012 B.3.1:
39 function Value (Item : in chars_ptr; Length : in size_t)
return String;
40/1 Equivalent to To_Ada(Value(Item, Length) & nul, Trim_Nul=>True).
Isn't the function Value improperly recursively defined through itself?!
Please explain.
Also: It seems that in Interfaces.C.Strings there is no function which
creates an Ada string of specified length from a chars_ptr (without checking
for NUL). Addition of such a function would be good, because it can be very
fast (on some platforms it can be implemented as memcpy).
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Troubles with C strings
2014-07-26 14:13 Troubles with C strings Victor Porton
@ 2014-07-26 15:15 ` Shark8
2014-07-26 15:52 ` Victor Porton
2014-07-26 19:06 ` Peter Chapin
2014-07-26 18:41 ` Niklas Holsti
1 sibling, 2 replies; 8+ messages in thread
From: Shark8 @ 2014-07-26 15:15 UTC (permalink / raw)
On 26-Jul-14 08:13, Victor Porton wrote:
> Also: It seems that in Interfaces.C.Strings there is no function which
> creates an Ada string of specified length from a chars_ptr (without checking
> for NUL). Addition of such a function would be good, because it can be very
> fast (on some platforms it can be implemented as memcpy).
Such a function cannot exist: to determine the length of a C-style
string you *must* scan through it for the terminating NULL. What you
describe would be a "substring" method that can read beyond the
string-bounds without raising an error... and I see no way that would
end well.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Troubles with C strings
2014-07-26 15:15 ` Shark8
@ 2014-07-26 15:52 ` Victor Porton
2014-07-26 17:09 ` Shark8
2014-07-26 19:06 ` Peter Chapin
1 sibling, 1 reply; 8+ messages in thread
From: Victor Porton @ 2014-07-26 15:52 UTC (permalink / raw)
Shark8 wrote:
> On 26-Jul-14 08:13, Victor Porton wrote:
>> Also: It seems that in Interfaces.C.Strings there is no function which
>> creates an Ada string of specified length from a chars_ptr (without
>> checking for NUL). Addition of such a function would be good, because it
>> can be very fast (on some platforms it can be implemented as memcpy).
>
> Such a function cannot exist: to determine the length of a C-style
> string you *must* scan through it for the terminating NULL. What you
> describe would be a "substring" method that can read beyond the
> string-bounds without raising an error... and I see no way that would
> end well.
It can. The length of the string may be "scanned" earlier and be stored, so
that we could later use it efficiently.
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Troubles with C strings
2014-07-26 15:52 ` Victor Porton
@ 2014-07-26 17:09 ` Shark8
0 siblings, 0 replies; 8+ messages in thread
From: Shark8 @ 2014-07-26 17:09 UTC (permalink / raw)
On 26-Jul-14 09:52, Victor Porton wrote:
> It can. The length of the string may be "scanned" earlier and be stored, so
> that we could later use it efficiently.
That still involves scanning.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Troubles with C strings
2014-07-26 14:13 Troubles with C strings Victor Porton
2014-07-26 15:15 ` Shark8
@ 2014-07-26 18:41 ` Niklas Holsti
1 sibling, 0 replies; 8+ messages in thread
From: Niklas Holsti @ 2014-07-26 18:41 UTC (permalink / raw)
On 14-07-26 17:13 , Victor Porton wrote:
> RM2012 B.3.1:
>
> 39 function Value (Item : in chars_ptr; Length : in size_t)
> return String;
> 40/1 Equivalent to To_Ada(Value(Item, Length) & nul, Trim_Nul=>True).
>
> Isn't the function Value improperly recursively defined through itself?!
No, the definition uses another Value function.
> Please explain.
The call in 40/1 uses
function Value (Item : in chars_ptr; Length : in size_t)
return char_array;
from RM B.3.1(35), followed by
function To_Ada (Item : in char_array;
Trim_Nul : in Boolean := True)
return String;
from RM B.3(26).
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Troubles with C strings
2014-07-26 15:15 ` Shark8
2014-07-26 15:52 ` Victor Porton
@ 2014-07-26 19:06 ` Peter Chapin
2014-07-26 19:09 ` Victor Porton
1 sibling, 1 reply; 8+ messages in thread
From: Peter Chapin @ 2014-07-26 19:06 UTC (permalink / raw)
On 2014-07-26 11:15, Shark8 wrote:
> On 26-Jul-14 08:13, Victor Porton wrote:
>> Also: It seems that in Interfaces.C.Strings there is no function which
>> creates an Ada string of specified length from a chars_ptr (without
>> checking for NUL).
>
> Such a function cannot exist: to determine the length of a C-style
> string you *must* scan through it for the terminating NULL. What you
> describe would be a "substring" method that can read beyond the
> string-bounds without raising an error... and I see no way that would
> end well.
Well the function could exist; it would just require an additional
parameter to specify how much should be copied. While such an approach
might be contrary to the sensibilities of Ada programmers, I don't think
C programmers would find it shocking.
Of course we are talking about an Ada interface here so adding a
function that by its nature could easily lead to undefined behave...
er... erroneous execution probably wouldn't be great.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Troubles with C strings
2014-07-26 19:06 ` Peter Chapin
@ 2014-07-26 19:09 ` Victor Porton
2014-08-01 22:16 ` Victor Porton
0 siblings, 1 reply; 8+ messages in thread
From: Victor Porton @ 2014-07-26 19:09 UTC (permalink / raw)
Peter Chapin wrote:
> On 2014-07-26 11:15, Shark8 wrote:
>
>> On 26-Jul-14 08:13, Victor Porton wrote:
>>> Also: It seems that in Interfaces.C.Strings there is no function which
>>> creates an Ada string of specified length from a chars_ptr (without
>>> checking for NUL).
>>
>> Such a function cannot exist: to determine the length of a C-style
>> string you *must* scan through it for the terminating NULL. What you
>> describe would be a "substring" method that can read beyond the
>> string-bounds without raising an error... and I see no way that would
>> end well.
>
> Well the function could exist; it would just require an additional
> parameter to specify how much should be copied. While such an approach
> might be contrary to the sensibilities of Ada programmers, I don't think
> C programmers would find it shocking.
>
> Of course we are talking about an Ada interface here so adding a
> function that by its nature could easily lead to undefined behave...
> er... erroneous execution probably wouldn't be great.
Jut call this function *_Unchecked or *_Unsafe and it would turn it safe.
:-)
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Troubles with C strings
2014-07-26 19:09 ` Victor Porton
@ 2014-08-01 22:16 ` Victor Porton
0 siblings, 0 replies; 8+ messages in thread
From: Victor Porton @ 2014-08-01 22:16 UTC (permalink / raw)
Victor Porton wrote:
> Peter Chapin wrote:
>
>> On 2014-07-26 11:15, Shark8 wrote:
>>
>>> On 26-Jul-14 08:13, Victor Porton wrote:
>>>> Also: It seems that in Interfaces.C.Strings there is no function which
>>>> creates an Ada string of specified length from a chars_ptr (without
>>>> checking for NUL).
>>>
>>> Such a function cannot exist: to determine the length of a C-style
>>> string you *must* scan through it for the terminating NULL. What you
>>> describe would be a "substring" method that can read beyond the
>>> string-bounds without raising an error... and I see no way that would
>>> end well.
>>
>> Well the function could exist; it would just require an additional
>> parameter to specify how much should be copied. While such an approach
>> might be contrary to the sensibilities of Ada programmers, I don't think
>> C programmers would find it shocking.
>>
>> Of course we are talking about an Ada interface here so adding a
>> function that by its nature could easily lead to undefined behave...
>> er... erroneous execution probably wouldn't be great.
>
> Jut call this function *_Unchecked or *_Unsafe and it would turn it safe.
> :-)
Hey, anyone!
Could we add this *_Unchecked or *_Unsafe to Ada202x?
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-08-01 22:16 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-26 14:13 Troubles with C strings Victor Porton
2014-07-26 15:15 ` Shark8
2014-07-26 15:52 ` Victor Porton
2014-07-26 17:09 ` Shark8
2014-07-26 19:06 ` Peter Chapin
2014-07-26 19:09 ` Victor Porton
2014-08-01 22:16 ` Victor Porton
2014-07-26 18:41 ` Niklas Holsti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox