comp.lang.ada
 help / color / mirror / Atom feed
* Compiler checking of String lengths during assignment (Newbie Question)
@ 2015-01-09 22:50 isaac1.0
  2015-01-09 23:10 ` Simon Wright
                   ` (6 more replies)
  0 siblings, 7 replies; 15+ messages in thread
From: isaac1.0 @ 2015-01-09 22:50 UTC (permalink / raw)


Maybe this is obvious to the experts, but I'm new to Ada.

I'm using the Libre GNAT GPS 2014. I've a program that looks roughly like this:
==============================================
procedure Main is
   Head : String (1..5) := "XXX_N";
   i : Positive;
   Line : String := "12312312312312312";
   
begin
.
.
.
   i := 2;
   Head := "123";
   Head := Line(1 .. 2);
   Head := Line(i+2 .. i+4);
.
.
.
end Main;
==============================================

The first 2 cases produces an error during the build, as expected, because Head is known to be length of 5 and I'm assigning something of a different length.
The 3rd assignment there does NOT produce an error, no warning no nothing even though this clearly violates the same check.

What does happen is that at runtime the execution is incorrect. It doesn't even terminate in a horrible disaster (which would be preferable). The full program actually just reads a text file (for now) and in this case because the assigned length is incorrect, it just reads a few lines then bails claiming unable to read the text file.

Aren't Ada compilers supposed to prevent stupid errors like this? Or is there some user stupidity here that I'm not seeing...?

Thanks,
Isaac


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

end of thread, other threads:[~2015-01-16 15:44 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-09 22:50 Compiler checking of String lengths during assignment (Newbie Question) isaac1.0
2015-01-09 23:10 ` Simon Wright
2015-01-09 23:20   ` Stefan.Lucks
2015-01-10 12:43     ` Brian Drummond
2015-01-09 23:53 ` Shark8
2015-01-10  0:18 ` Jeffrey Carter
2015-01-10  1:48 ` Adam Beneschan
2015-01-10 10:03 ` Pascal Obry
2015-01-10 10:54 ` Simon Wright
2015-01-15 20:44 ` isaac1.0
2015-01-15 21:18   ` Simon Wright
2015-01-15 22:30     ` Jeffrey Carter
2015-01-15 22:32     ` Jeffrey Carter
2015-01-16  7:28       ` Simon Wright
2015-01-16 15:44         ` Jeffrey Carter

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