comp.lang.ada
 help / color / mirror / Atom feed
* Surprising behaviour of strings.fixed.overwrite
@ 2014-11-12 10:49 Markus Schöpflin
  2014-11-12 12:55 ` G.B.
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Markus Schöpflin @ 2014-11-12 10:49 UTC (permalink / raw)


Given the following Ada program:

---%<---
with TEXT_IO;
with ADA.STRINGS;
with ADA.STRINGS.FIXED;

procedure TEST
is
    S : STRING(1 .. 6);
begin
    S := "@@@@@@";
    ADA.STRINGS.FIXED.OVERWRITE (S, S'First + 5, "56", ADA.STRINGS.LEFT);
    TEXT_IO.PUT_LINE (S);

    S := "@@@@@@";
    ADA.STRINGS.FIXED.OVERWRITE (S, S'First + 5, "56", ADA.STRINGS.RIGHT);
    TEXT_IO.PUT_LINE (S);
end;
--->%---

What would you expect to be the output of the program?

Scroll down for the answer...

















































Well, I would have expected the output to be

@@@@@6
@@@@@5

But it is:

@@@@56
@@@@@5

Which is correct according to the definition of overwrite, but nevertheless I 
find this extremely surprising.

Am I alone in this?

Or can anyone please the rational on defining the behaviour of overwrite as it is?

Markus

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-11-13 12:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-12 10:49 Surprising behaviour of strings.fixed.overwrite Markus Schöpflin
2014-11-12 12:55 ` G.B.
2014-11-12 15:49 ` Adam Beneschan
2014-11-12 23:19 ` Randy Brukardt
2014-11-13  8:15   ` Markus Schöpflin
2014-11-13 12:40     ` Simon Wright
2014-11-13 12:56       ` Markus Schöpflin

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