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,ca15935e4fb21334 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Storage space question Date: 1998/12/11 Message-ID: #1/1 X-Deja-AN: 421013571 Sender: matt@mheaney.ni.net References: <366FE278.FAF73497@pwfl.com> <74pfg4$3s6$1@nnrp1.dejanews.com> NNTP-Posting-Date: Thu, 10 Dec 1998 17:15:37 PDT Newsgroups: comp.lang.ada Date: 1998-12-11T00:00:00+00:00 List-Id: callen@space.honeywell.com writes: > OK, well, maybe I'll elaborate a bit more on what it is I'm trying to > accomplish. I have a hardware device that has registers I will > access. Lets say one register looks like this (identifiers have been > changed to protect the innocent): > > > type REGISTER_1_Type is > record > field_1_Ctrl: t_3bit; > field_2_Ctrl: t_3bit; > field_3_Ctrl: t_2bit; > field_4_Ctrl: t_2bit; > field_5_Ctrl: t_2bit; > DCD_Pin_Ctrl: t_2bit; > field_7_Ctrl: t_2bit; > end record; > > Assume these imaginary t_ types are 3 and 2 bits worth of values > respectively. Now, in order to write to this register, I would write > > Reg.DCD_Pin_Ctrl := 2#01#; > > OK, but I'd like to use more descriptive names for these. Like so. > > Reg.DCD_Pin_Ctrl := SYNC_DETECT; > > So, I define and represent the enum above (as 2 separate Ada books > have suggested...). Now, the code looks nicer, but I have this baggage > that came with it that I don't need. I really just want the ability > to do as a #define (or enum) would do in C - that is to do the > substitution for me to make the code look nicer, but not increase the > memory footprint (over using constants in the program). The reason is > that I would like to make *many* of these. For the sake of argument, > say there's 100 registers each with 8 bits worth of possibilities. I > don't want tables with all that info in there, just the 100 values > that I'm using to initialize the thing to be put in the right place in > the code. I liked the use of the enumerated types for these, as their > namespaces won't clash (Each register can have it's own DEFAULT for > instance). > > Again, I'm using Ada83, and don't see a pragma that will help me. I > understand and agree with the dislike of preprocessors, but is what > I'm trying to do (which textual subst would work for...) such a bad > thing to ask for? Then just ditch the enumeration type, and use named constants of an integer type: type CDC_Control is range 0 .. 3; Sync_Control : constant CDC_Control := 2#01#; ... You don't really need enumeration types that have rep clauses; most of the time an integer type will do.