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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,acf9260990cb1991 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Static expressions and using 'Size Date: 1996/03/22 Message-ID: #1/1 X-Deja-AN: 143732003 references: <4isu7e$4d0@fozzie.sun3.iaf.nl> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-03-22T00:00:00+00:00 List-Id: In article <4isu7e$4d0@fozzie.sun3.iaf.nl>, Geert Bosch wrote: >Because of portability, readability and safety I'd like not to calculate >all record-sizes etc. myself, but have the compiler do that for me. The >problem is however that expressions involving the 'Size attribute are >not static and for that reason cannot be used in constants. You are confusing "named numbers" and "constants". The former need to be static; the latter do not. (S'Size *is* static, by the way, if S is a static (scalar) subtype.) Even if an expression is non-static, a good compiler will calculate it at compile time in *some* cases. >This is annoying because I'd rather write > Page_Info_Bytes : constant := Page_Info'Size / Byte'Size; >than > Page_Info_Bytes : Positive := Page_Info'Size / Byte'Size; You can do this: Page_Info_Bytes : constant Positive := Page_Info'Size / Byte'Size; ^^^^^^^^ Better yet, I suggest you define a type like Size_In_Bytes, different from Positive, and use that. > -- All XXX_Size identifiers denote sizes in bytes rather than bits I suggest you use the type system to reflect the above comment. > VM_Size : constant := 2 ** 29; -- 512 MB Virtual Memory > Page_Size : constant := 2 ** 12; -- 4 kB VM pages And make these be of type Size_In_Bytes, too. > type Page_Nr is range 0.. VM_Size / Page_Size - 1; -- 2 ** 17 pages I suggest you delete the comment "-- 2 ** 17 pages", because it is a maintenance problem. The whole point of saying "VM_Size / Page_Size" is that if VM_Size or Page_Size changes, you *don't* have to change Page_Nr. But because of that comment, you *do* have to change the declaration of Page_Nr. Or, you might forget, and leave a wrong comment, which is always worse than no comment. (It's not so bad in *this* case, because the related code is nearby, but still...) - Bob