comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: CONSTRAINT_ERROR - why?
Date: Sat, 14 Dec 2002 19:15:11 GMT
Date: 2002-12-14T19:15:11+00:00	[thread overview]
Message-ID: <wccof7obef4.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 3%KK9.53003$vM1.4249406@bgtnsc04-news.ops.worldnet.att.net

"James S. Rogers" <jimmaureenrogers@worldnet.att.net> writes:

> "Alfred Hilscher" <Alfred.Hilscher@t-online.de> wrote in message
> news:3DFB7841.F898C02@t-online.de...
> > This program raises exception CONSTRAINT_ERROR for the second
> > assignment. It happens with GNAT 3.13p and 3.14p (on windows).
> >
> > Can someone explain why? Is this a compiler error or do I misunderstand
> > something?
> >
> > I would expect that the computation is done first and then the result
> > (33 which is successfully assigned the statement before) is assigned.
> > But it seems that the size (=264) is assigned before the division is
> > executed.

The 'Size is implicitly converted to BYTE, and then the "/" operator of
type BYTE is used.  You want to do the division in, say, Integer,
and then explicitly convert to BYTE, like:

    ... := BYTE(Integer'(Fac_Conf_Struct'Size / 8));

> > with Interfaces.C; use Interfaces.C;
> >
> > with Text_IO; use Text_IO;
> >
> > procedure Test is
> >
> >     type    BYTE       is new Interfaces.C.Unsigned_Char;
> >
> >     type Fac_Conf_Struct is
> >       record
> >         Struct_Length     : BYTE;
> >         Filler            : String (1..32);
> >       end record;
> >
> >
> >   X : Fac_Conf_Struct;
> > begin
> >   Put_Line ("Struct_Length=" & Integer'Image (Fac_Conf_Struct'Size /
> > 8));
> >   X.Struct_Length := 33;
> >   X.Struct_Length := (Fac_Conf_Struct'Size / 8);  -- Value is 33, too.
> > But - constraint_error is raised
> > end Test;
> 
> It compiles and runs without exception using GNAT 3.15p.

Perhaps checking is turned off?

- Bob



  reply	other threads:[~2002-12-14 19:15 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-14 18:28 CONSTRAINT_ERROR - why? Alfred Hilscher
2002-12-14 18:45 ` James S. Rogers
2002-12-14 19:15   ` Robert A Duff [this message]
2002-12-14 19:20     ` James S. Rogers
2002-12-14 19:42     ` Alfred Hilscher
2002-12-16  2:39       ` AG
2002-12-14 19:20   ` Alfred Hilscher
2002-12-14 20:58     ` Dennis Lee Bieber
2002-12-15 13:45       ` Alfred Hilscher
2002-12-15 19:04         ` Robert A Duff
2002-12-16  1:12         ` Dennis Lee Bieber
2002-12-16  2:20           ` Jeffrey Carter
2002-12-16 18:48             ` Alfred Hilscher
2002-12-16 19:53               ` James S. Rogers
2002-12-17 18:20                 ` Alfred Hilscher
2002-12-17 19:29                   ` Robert A Duff
2002-12-17 21:05                     ` Dennis Lee Bieber
2002-12-18 18:36                     ` Alfred Hilscher
2002-12-18 18:51                       ` Robert A Duff
2002-12-18 21:45                         ` Randy Brukardt
2002-12-19 16:49                           ` Robert Spooner
2002-12-19 20:57                             ` Randy Brukardt
2002-12-14 20:19 ` Jeffrey Carter
2002-12-14 22:26   ` Alfred Hilscher
2002-12-15  0:49     ` Dennis Lee Bieber
2002-12-15  2:18     ` Jeffrey Carter
2002-12-15 18:23       ` Jeffrey Carter
2002-12-15 14:01   ` Alfred Hilscher
2002-12-15 18:20     ` Jeffrey Carter
2002-12-15 19:00       ` Alfred Hilscher
2002-12-16  1:16         ` Dennis Lee Bieber
2002-12-16 18:50           ` Alfred Hilscher
2002-12-17  2:17             ` Dennis Lee Bieber
2002-12-17 18:21               ` Alfred Hilscher
     [not found]                 ` <26tuvu4ekeigls0bnd2okavrdhfu0tir4a@4ax.com>
2002-12-18 18:47                   ` Alfred Hilscher
replies disabled

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