comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: strange length check error
Date: Wed, 17 Jan 2018 13:41:58 +0000
Date: 2018-01-17T13:41:58+00:00	[thread overview]
Message-ID: <lyy3kw8uvt.fsf@pushface.org> (raw)
In-Reply-To: ca6ffdc8-6e50-45cf-9ab5-43854525bdb9@googlegroups.com

AdaMagica <christ-usch.grein@t-online.de> writes:

> Am Mittwoch, 17. Januar 2018 13:13:49 UTC+1 schrieb Mehdi Saada:
>> I get it, it's ugly, inefficient, wrong, I KNOW, but it's not mine,
>> and I can't affor rewriting *every* piece of code that come along
>> the exercices.
>> Well, I could replace the actual
>> type BOUNDED_STRING is record
>>     LENGTH: NATURAL := 0;
>>     DATA: STRING (1 .. 80); <---- I guess *you* forgot this or else
>> it's illegal
>> end record;
>
> Then of course this will raise an exception:
> return (LENGTH(LEFT) + 1, LEFT.DATA(1..LENGTH(LEFT)) & RIGHT);
> since
> LEFT.DATA(1..LENGTH(LEFT)) & RIGHT is shorter than 80.
>
> Who is the *teacher*?

I'm guessing that this is a generic, with parameter MAX_LENGTH, so maybe

   type BOUNDED_STRING is record
      LENGTH: NATURAL := 0;
      DATA: STRING (1 .. MAX_LENGTH);
   end record;

& then this should be OK

   return
     (LENGTH(LEFT) + 1,
      LEFT.DATA(1..LENGTH(LEFT))
        & RIGHT
        & LEFT.DATA((LENGTH(LEFT) + 1)..MAX_LENGTH));

  reply	other threads:[~2018-01-17 13:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-16 20:48 strange length check error Mehdi Saada
2018-01-17  1:42 ` Anh Vo
2018-01-17  9:23   ` Simon Wright
2018-01-17 12:13     ` Mehdi Saada
2018-01-17 13:19       ` AdaMagica
2018-01-17 13:41         ` Simon Wright [this message]
2018-01-17 21:37           ` Jeffrey R. Carter
2018-01-18 11:12             ` Simon Wright
2018-01-17 13:43         ` Mehdi Saada
2018-01-17 14:03           ` Mehdi Saada
2018-01-17 16:15             ` Mehdi Saada
2018-01-17 19:43               ` Simon Wright
2018-01-17 21:37                 ` Mehdi Saada
2018-01-17 23:00                   ` Niklas Holsti
2018-01-18 11:07                     ` Simon Wright
2018-01-17 13:15     ` Simon Clubley
2018-01-17  8:49 ` Dmitry A. Kazakov
2018-01-23 16:18 ` Robert Eachus
2018-01-23 16:41   ` Mehdi Saada
2018-01-24 16:22     ` Robert Eachus
replies disabled

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