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,19502ac20a7b16de X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-19 03:38:01 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed!btnet-peer0!btnet-feed5!btnet!news.btopenworld.com!not-for-mail From: john@nospam.demon.co.uk (John McCabe) Newsgroups: comp.lang.ada Subject: Re: Dynamic discrimants in variant records? Date: Thu, 19 Jun 2003 10:37:32 +0000 (UTC) Organization: BT Openworld Message-ID: <3ef190e6.9372917@news.btclick.com> References: NNTP-Posting-Host: host217-37-177-69.in-addr.btopenworld.com X-Trace: hercules.btinternet.com 1056019052 19336 217.37.177.69 (19 Jun 2003 10:37:32 GMT) X-Complaints-To: news-complaints@lists.btinternet.com NNTP-Posting-Date: Thu, 19 Jun 2003 10:37:32 +0000 (UTC) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:39440 Date: 2003-06-19T10:37:32+00:00 List-Id: On Thu, 19 Jun 2003 10:44:21 +0200, Vinzent Hoefler wrote: >Well, so far so good, I can perfectly define a corresponding type >statically. Deciding which of the registers to use for what region of >memory statically is probably quite ok for most real world cases, but >I really would like to have a little bit more flexibility. > >As mentioned, the actual (global) variables of this type are memory >mapped registers, so the problem occurs when I want to change a region >register dynamically (from a 4K granularity to a 64K for instance). In >Ada this would be equivalent to just change some of the discrimants >(those are really some bits in the register) and so changing the >interpretation of the record. > >AFAICS this is not allowed in Ada, once a variable of a specific type >is declared I cannot change its discriminants anymore. Is there any >nice Ada-ish way around this? >Or IOW, how would someone do that what I want in the most efficient >way? Declaring an appropriate type each time and use an unchecked >conversion to apply it to the "real" memory mapped register? It may be worth reading about mutable and immutable discrimnated types. Whether you can change the discriminant of an object after it is created depends on whether default values have been assigned to the discriminants etc. I can't remember the exact details but "Ada as a Second Language" is, I seem to remember, quite good on this. It may also be worth reading the following message and thread. http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=mailman.10.1046461270.1343.comp.lang.ada%40ada.eu.org Best Regards John McCabe To reply by email replace 'nospam' with 'assen'