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,start X-Google-Attributes: gid103376,public From: geert@fozzie.sun3.iaf.nl (Geert Bosch) Subject: Static expressions and using 'Size Date: 1996/03/22 Message-ID: <4isu7e$4d0@fozzie.sun3.iaf.nl>#1/1 X-Deja-AN: 143692725 organization: La Calandre Infortunee newsgroups: comp.lang.ada Date: 1996-03-22T00:00:00+00:00 List-Id: Currently I'm writing a GC compatible allocator for GNAT and I found some Ada-related problems for which I didn't find a nice work-around yet. Maybe somebody can give some hints. One part of the allocator (which is working fine BTW) is the Page_Manager which maintains some administration about the virtual memory that has been allocated, is behind write-barriers etc. Because of some comments from others I try to make the code suitable for systems that use other page-sizes than 4 kB, 32-bit addresses etc. One of the problems is that the sizes of some data-structures depend on sizes of others. 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. 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; because the value of Page_Info_Bytes is known at compile-time and won't change during execution of the program (I hope ;-) Things become worse when I want declare types that depend on these 'constants'. Would I really have to explicitly specify all record-sizes and stuff myself, with all problems when size of data-structures change? I *must* overlook something, but I can't think of it. If I indeed need to specify everything myself, I think this is contrary to the 'Ada-philosophy' Thanks in advance for any reactions! Geert --- Here comes some of the relevant Ada-code -------------------------- package Page_Manager is -- (Edited, stripped down version) -- All XXX_Size identifiers denote sizes in bytes rather than bits VM_Size : constant := 2 ** 29; -- 512 MB Virtual Memory Page_Size : constant := 2 ** 12; -- 4 kB VM pages type Page_Nr is range 0.. VM_Size / Page_Size - 1; -- 2 ** 17 pages -- Every VM page has a Page_Info record type Page_Info is record ... end record; -- Here are subprograms for Set_Page_Info, Get_Page_Info etc. end Page_Manager; package body Page_Manager is -- This is illegal Ada'95 code !!! Page_Info_Size : constant := Page_Info'Size / Byte'Size; Page_Map_Size : constant := Page_Map'Size / Byte'Size; Map_Entries_Per_VM_Page : constant := Page_Size / Page_Info_Size; Map_Pages : constant := Page_Nr'Last / Map_Entries_Per_VM_Page; type Map_Page_Nr is range 0..Map_Pages - 1; -- Rest deleted end Page_Manager; -- E-Mail: geert@sun3.iaf.nl *** Real programers don't document their code: if *** Phone: +31-53-4303054 ** it was hard to write, it should be hard to read **