comp.lang.ada
 help / color / mirror / Atom feed
From: "McDoobie" <someone@nospam.net>
Subject: Re: Some problems with string type(Exact String?)
Date: Wed, 06 Jun 2001 20:29:05 GMT
Date: 2001-06-06T20:29:05+00:00	[thread overview]
Message-ID: <lowT6.40598$DG1.6446489@news1.rdc1.mi.home.com> (raw)
In-Reply-To: 3B1E5BAA.49F1EF9B@amsjv.com

In article <3B1E5BAA.49F1EF9B@amsjv.com>, Philip Anderson
<phil.anderson@amsjv.com> wrote:

> Valdes wrote:
>> 
>> I have my program writen in Ada that raise some exceptions:
>> 
>> raised CONSTRAINT_ERROR : gestindex.adb:5
>> 
>> ... And at line 5...
>> 
>>  function createindex (S:string) return index is
>>       I:Index;
>>    begin
>>       i.nameindex:=s; -- Ligne cinq
> 
> Note that Constraint Error will be raised if s is not _exactly_ 20
> characters long.
> 
>>       i.firstletter:=null; return i;
>>    end createindex;
>> 
>> ... The index record is defined as follow...
>> 
>>   type index is record
>>       nameindex:String(1..20); firstletter:ptrletter;
>>    end record;
>> 
>> ... The mistake seems to be trivial but I don't see it.
>> 
>> I have seen the same for this also:
>> 
>>     Ptrtemp.Letter:=Charat(M,Ni);
>> 
>> there is the same error but Charat return a character and letter is
>> also one. (ptrtemp is also type ptrlettre)
> 
> Is M a String and Ni an index into it?  If so Ni must be within the
> range M'first .. M'last, and M'first may be greater than 1 (and won't be
> 0).
> 
> 
>> All my greetings if you have some ideas. And forgive me for my bad
>> english.
> 
> Pas de probleme.

Alright, so in this example, the string has to be EXACTLY 20 characters.

Now, in a couple other languages I've used, the string can be String<20
characters but  not 20<String, rather than having to be String=20. So if I
understand correctly, a string (or  more appropriately the elements of an
ARRAY) have to precisely match the declared  bounds of the array. Yes, no?

I'm currently reading through the "Arrays and Records" chapter of
"Programming in Ada95" by Barnes. It's throwing alot of information at me,
and I'm hitting a couple kinks in digesting  it all. But from what I can
glean, in Ada95 arrays are fixed. Unlike C where I could go less  than but
not greater than the bounds of the array.  My first hunch on the way to
work with this strictness(or so it seems) would be keep count of the
number of elements (characters of a string, numbers, whatever) going into
the array, and then pad the rest of the array with with NULLs or something
similar when there is no more  information to add to the array.

Am I thinking along the right track here? Or am I missing something
important?

McDoobie chris@dont.spam.me



  reply	other threads:[~2001-06-06 20:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-07  2:18 Some problems with string type Valdes
2001-06-06 16:34 ` Philip Anderson
2001-06-06 20:29   ` McDoobie [this message]
2001-06-06 21:30     ` Some problems with string type(Exact String?) tmoran
2001-06-07  8:07       ` Jean-Pierre Rosen
2001-06-06 22:08     ` Marin David Condic
2001-06-07  6:48     ` Ada.Strings.Fixed procedure Move Petter Fryklund
2001-06-07  4:06   ` Some problems with string type Valdes
2001-06-07 13:20     ` Valdes Laurent
2001-06-06 17:49 ` tmoran
2001-06-07  4:07   ` Valdes
replies disabled

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