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.1 required=5.0 tests=BAYES_00, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,47bb539f07b52c30 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-15 07:25:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!opentransit.net!wanadoo.fr!oleane.net!oleane!nnrp.oleane.net!not-for-mail From: "Jean-Pierre Rosen" Newsgroups: comp.lang.ada Subject: Re: How to get a compilation error Date: Thu, 15 Nov 2001 16:09:50 +0100 Organization: Adalog Message-ID: <9t0mm9$hq8$1@s1.read.news.oleane.net> References: <3bf3d68c$1@pull.gecm.com> NNTP-Posting-Host: mailhost.axlog.fr X-Trace: s1.read.news.oleane.net 1005837834 18248 195.25.228.57 (15 Nov 2001 15:23:54 GMT) X-Complaints-To: abuse@oleane.net NNTP-Posting-Date: Thu, 15 Nov 2001 15:23:54 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Xref: archiver1.google.com comp.lang.ada:16569 Date: 2001-11-15T16:09:50+01:00 List-Id: "Martin Dowie" a �crit dans le message news: 3bf3d68c$1@pull.gecm.com... > "Wilhelm Spickermann" wrote in message > news:mailman.1005833842.603.comp.lang.ada@ada.eu.org... > Hi, > > I would like to get a compilation *error*, if some compile time > constant is not suitable for the algorithm in use. Example: > > Chunk_Bits : constant := > Integer'Min (32, System.Max_Binary_Modulus / 2); > type Check is (Checkitem1, Checkitem2); > for Check'SIZE use 1 - Integer'MIN (96 mod Chunk_Bits, 1); > > The last two lines result in a compilation error, if and (I > hope) only if 96 is not a multiple of Chunk_Bits. That�s what I > want -- but it�s really ugly. Does anyone have something better? > > > Could try: > > type A_Valid_Range is range 0 .. 0; > > My_Check : constant A_Valid_Range := > A_Valid_Range (96 mod (Integer'Min (32, System.Max_Binary_Modulus / > 2))); > > This will probably raise a warning rather than an error though. > Some compilers will let you specify that warning are to be > treated as errors. To get an error, do the following: subtype Assert is boolean range True..True; Check : constant := Assert'Pos(96 rem Chunk_Bits = 0) Since Check is a named number, an invalid value will result in a compile time error (new in 95). -- --------------------------------------------------------- J-P. Rosen (rosen@adalog.fr) Visit Adalog's web site at http://www.adalog.fr