Re: Constraint Error
tmoran_at_acm.org
Date: 09/30/04
- Next message: stephane richard: "Re: GWindows and a future home for it"
- Previous message: Matthew Heaney: "Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl)"
- Next in thread: John A. S. Rowlands: "Re: Constraint Error"
- Maybe reply: John A. S. Rowlands: "Re: Constraint Error"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 30 Sep 2004 01:11:17 GMT
> m2:=Messages.Create("This is a second test");
will raise Constraint_Error because you attempt to store its 21 characters
into M.Text, which is a 20 character string. Ada is preventing a buffer
overflow error.
> m1:=Messages.Create("This is a test");
raises Constraint_Error because you attempt to store a 14 character
string into a 20 character M.Text If you had said, for instance,
M.Text(1 .. Str'length) := Str;
then it would have stored into the first 14 characters, leaving junk
in the next 6 and no way for a later user of M.Text to know which,
if any, of its characters are non-junk.
Or
M.Text := Str & (Str'length+1 .. M.Text'length => ' ');
would fill in any unused characters with ' ', which might be what
you would like.
To assign an array (or String, which is just an array of characters)
to another array, their sizes must match. If they don't match, you
will need to truncate, pad, or just partially fill, as needed. In
that case you probably want to use a counter or special terminating
character, to remember the "actual" size of the string in M.Text
In the particular case of varying length strings, of course, it would
be easiest to just use Ada.Strings.Bounded or Ada.Strings.Unbounded
- Next message: stephane richard: "Re: GWindows and a future home for it"
- Previous message: Matthew Heaney: "Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl)"
- Next in thread: John A. S. Rowlands: "Re: Constraint Error"
- Maybe reply: John A. S. Rowlands: "Re: Constraint Error"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|