comp.lang.ada
 help / color / mirror / Atom feed
* Constraint error
@ 1999-04-07  0:00 Nirmala Bhupathi
  1999-04-07  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 10+ messages in thread
From: Nirmala Bhupathi @ 1999-04-07  0:00 UTC (permalink / raw)


Hi,

I am getting a constraint error with this program.
Is it behaving right?


with Ada.Text_IO;
with Interfaces;

procedure Show is

  type Local_T is mod 32;

  type Alpha_T   is new Local_T;
  type Bravo_T   is new Interfaces.Unsigned_32;
  type Charlie_T is digits 6;

  package Alpha_IO   is new Ada.Text_IO.Modular_IO(Alpha_T);
  package Bravo_IO   is new Ada.Text_IO.Modular_IO(Bravo_T);
  package Charlie_IO is new Ada.Text_IO.Float_IO(Charlie_T);

  A : Alpha_T;
  B : Bravo_T;
  C : Charlie_T;

begin

  Ada.Text_IO.Put ("Enter: ");

  Charlie_IO.Get(C);

  A := Alpha_T(C);

  Alpha_IO.Put(A);

  Ada.Text_IO.New_Line;

  B := Bravo_T(C);

  Bravo_IO.Put(B);

  Ada.Text_IO.New_Line;

end Show;




^ permalink raw reply	[flat|nested] 10+ messages in thread
* Constraint Error
@ 2004-09-29 23:24 Rick Santa-Cruz
  2004-09-30  0:42 ` Jeffrey Carter
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Rick Santa-Cruz @ 2004-09-29 23:24 UTC (permalink / raw)


Hi,

how can I avoid the Constraint Error, when executing the following code:

with Messages;

procedure Test_Messages is
 M1: Messages.Message;
 M2: Messages.Message;

begin
 m1:=Messages.Create("This is a test");
 m2:=Messages.Create("This is a second test");
end Test_Messages;
----------------------------
 package Messages is
 type Message is tagged private;
 subtype String_Txt is String(1..20);

 function Create(Str: String) return Message;

 private
  type Message is tagged
   record
    Text: String_Txt;
   end record;
end Messages;
------------------------------
package body Messages is
 function Create(Str: String) return Message is
  M: Message;
 begin
  M.Text := Str;
  return M;
 end Create;
end Messages;

The Constraint Error occurs in the Create-Function.

Thanks in advance,
Rick 





^ permalink raw reply	[flat|nested] 10+ messages in thread
* Constraint_Error
@ 1987-04-10 21:47 keith
  0 siblings, 0 replies; 10+ messages in thread
From: keith @ 1987-04-10 21:47 UTC (permalink / raw)



Well, if you want me to read the LRM to you:

3.5.4:12 "... in which case an attempt to assign the result to a variable
          of the integer subtype raises the exception CONSTRAINT_ERROR."

So from your original incorrect Ada "type x is range 0..100"; either
possible translation "subtype x is range 0..100" or
"type x is new integer range 0..100", the language standard clearly states
that assigning a value outside of the specified range (check 3.3.2:9) will
raise CONSTRAINT_ERROR.

Sorry for my earlier post.  I assumed you had read the manual.

Keith

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

end of thread, other threads:[~2004-09-30 13:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-07  0:00 Constraint error Nirmala Bhupathi
1999-04-07  0:00 ` Matthew Heaney
1999-04-07  0:00   ` Nirmala Bhupathi
1999-04-08  0:00     ` Matthew Heaney
  -- strict thread matches above, loose matches on Subject: below --
2004-09-29 23:24 Constraint Error Rick Santa-Cruz
2004-09-30  0:42 ` Jeffrey Carter
2004-09-30  0:42 ` Stephen Leake
2004-09-30  1:11 ` tmoran
2004-09-30 13:47 ` John A. S. Rowlands
1987-04-10 21:47 Constraint_Error keith

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