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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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:20:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn13feed!wn11feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!not-for-mail Reply-To: "James S. Rogers" From: "James S. Rogers" Newsgroups: comp.lang.ada References: <3DFB7841.F898C02@t-online.de> <3%KK9.53003$vM1.4249406@bgtnsc04-news.ops.worldnet.att.net> Subject: Re: CONSTRAINT_ERROR - why? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: Date: Sat, 14 Dec 2002 19:20:05 GMT NNTP-Posting-Host: 12.86.35.221 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1039893605 12.86.35.221 (Sat, 14 Dec 2002 19:20:05 GMT) NNTP-Posting-Date: Sat, 14 Dec 2002 19:20:05 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:31822 Date: 2002-12-14T19:20:05+00:00 List-Id: "Robert A Duff" wrote in message news:wccof7obef4.fsf@shell01.TheWorld.com... > "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: This is what I expected. I checked GNAT 3.15p just as a sanity check. > > ... := 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? > I checked that too. Nope. Checking was not turned off. Jim Rogers