comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Storage space question
Date: 1998/12/11
Date: 1998-12-11T00:00:00+00:00	[thread overview]
Message-ID: <m34sr3o4us.fsf@mheaney.ni.net> (raw)
In-Reply-To: 74pfg4$3s6$1@nnrp1.dejanews.com

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.











  parent reply	other threads:[~1998-12-11  0:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-10  0:00 Storage space question Craig Allen
1998-12-10  0:00 ` Marin David Condic
1998-12-10  0:00   ` Matthew Heaney
1998-12-10  0:00     ` dennison
1998-12-10  0:00   ` Tucker Taft
1998-12-10  0:00     ` callen
1998-12-10  0:00       ` dennison
1998-12-10  0:00       ` Marin David Condic
1998-12-10  0:00         ` Tucker Taft
1998-12-11  0:00           ` dennison
1998-12-11  0:00         ` Matthew Heaney
1998-12-11  0:00           ` Marin David Condic
1998-12-12  0:00             ` Matthew Heaney
1998-12-12  0:00               ` David C. Hoos, Sr.
1998-12-12  0:00                 ` Matthew Heaney
1998-12-14  0:00                 ` dennison
1998-12-11  0:00       ` Matthew Heaney [this message]
1998-12-10  0:00   ` Pat Rogers
1998-12-10  0:00     ` dennison
1998-12-10  0:00       ` Pat Rogers
1998-12-10  0:00 ` dennison
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox