comp.lang.ada
 help / color / mirror / Atom feed
From: dennison@telepath.com
Subject: Re: help: String Sets in ADA???
Date: 1998/09/25
Date: 1998-09-25T00:00:00+00:00	[thread overview]
Message-ID: <6ugfd0$7tn$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 360B9AFA.1F99D1CD@ios.chalmers.se

In article <360B9AFA.1F99D1CD@ios.chalmers.se>,
  Arash Vahidi <vahidi@ios.chalmers.se> wrote:

Having troube with our homework, are we? :-)

> Here is my code, but lloks like I get Cosntraint_Error as soon as I make
> an assigment (see the code).
...
>    type Node is record
>       Object : String( 1..1024 );
>       -- Object : String_Pointer;
>       Next   : Node_Pointer;
>    end record;
...
>    procedure Insert( Object : in String) is
>       Tmp : Node_Pointer;
>    begin
...
>          First.Object := object;
This line  ^^^^^^^^^^^^^^^^^^^^^^^ will raise a constraint error if the string
passed in to Insert isn't *exactly* 1024 characters long. You could change it
to:
   First.Object(1..Object'length) := Object;

If you want the rest of the string blanked out, you could add another line:
   First.Object (Object'length + 1..First.Object'last) := (others => ' ');

The problem with all this is that after the call you don't have any way of
finding out how many characters in a node's object contain valid data. I'd
suggest looking into using the type Ada.Strings.Unbounded.Unbounded_String
instead of String(1..1024).

--
T.E.D.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




  reply	other threads:[~1998-09-25  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-25  0:00 help: String Sets in ADA??? Arash Vahidi
1998-09-25  0:00 ` dennison [this message]
1998-09-25  0:00 ` Bob Fletcher
replies disabled

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