From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7be3870dd9c9518f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-14 11:17:02 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.cwix.com!news.umass.edu!world!news From: Robert A Duff Subject: Re: CONSTRAINT_ERROR - why? User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Sat, 14 Dec 2002 19:15:11 GMT Content-Type: text/plain; charset=us-ascii References: <3DFB7841.F898C02@t-online.de> <3%KK9.53003$vM1.4249406@bgtnsc04-news.ops.worldnet.att.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Organization: The World Public Access UNIX, Brookline, MA Xref: archiver1.google.com comp.lang.ada:31821 Date: 2002-12-14T19:15:11+00:00 List-Id: "James S. Rogers" writes: > "Alfred Hilscher" 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