comp.lang.ada
 help / color / mirror / Atom feed
* Terminator_Error
@ 2000-04-12  0:00 Adam Beneschan
  0 siblings, 0 replies; only message in thread
From: Adam Beneschan @ 2000-04-12  0:00 UTC (permalink / raw)


True or false: The following code should always raise a
Terminator_Error exception, where S is an
Interfaces.C.String.Chars_Ptr that points to any nul-terminated C
string.  I think the answer is true.  Here, Do_Something_With_String
is a procedure that takes a String parameter.

    Length := Interfaces.C.Strings.Strlen (S);
    Do_Something_With_String (Interfaces.C.Strings.Value (S, Length));

The reason I think Value raises an exception is:

B.3.1(40) says the call to Value is equivalent to

    To_Ada (Value (S, Length), Trim_Nul => True)

where the Value call here is the one that returns a Char_Array.

B.3.1(36) says that this last Value call returns "the shorter of two
arrays: the first Length chars pointed to by Item, and Value(Item)."
Value(Item) will always return Length+1 chars, since it returns all
the characters pointed to by Item, plus the nul terminator
(B.3.1(34)).  Thus, the first Length chars pointed to by Item is
always the shorter array, and the result of Value (S, Length) is
therefore the characters of S, *without* the nul terminator.  This
causes To_Ada to raise an exception, since B.3(51) says that To_Ada
propagates Terminator_Error if Trim_Nul is true and its parameter does
not contain a nul.

Am I right, or am I misunderstanding something?

Sorry if this has been covered before.

                                -- thanks, Adam


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-04-12  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-12  0:00 Terminator_Error Adam Beneschan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox