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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,869d7890f1bd9878 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-17 18:03:10 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!news.telebyte.nl!proxad.net!freenix!enst.fr!not-for-mail From: "David C. Hoos, Sr." Newsgroups: comp.lang.ada Subject: Re: Type-safe low-level programming? Date: Mon, 17 Feb 2003 20:04:39 -0600 Organization: ENST, France Message-ID: References: Reply-To: "comp.lang.ada mail to news gateway" NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 1045533781 1893 137.194.161.2 (18 Feb 2003 02:03:00 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Tue, 18 Feb 2003 02:03:00 +0000 (UTC) To: "comp.lang.ada mail to news gateway" Return-Path: X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.1 Precedence: list List-Id: comp.lang.ada mail to news gateway List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:34184 Date: 2003-02-17T20:04:39-06:00 You could do something like this: pragma No_Run_Time; subtype Bit_Number is Natural range 0 .. 7; type Bit is mod 2; subtype Address_Type is Natural range 0 .. 16#Ff#; subtype Bit_Index is Natural range 0 .. (Bit_Number'Last + 1) * (Address_Type'Last + 1) - 1; type Registers is array (Bit_Index) of Bit; pragma Pack (Registers); Storage_Unit : constant Natural := Bit_Number'Last + 1; Register_A : constant Address_Type := 0; Bit_A1 : constant Bit_Index := 4 + Register_A * Storage_Unit; Bit_A2 : constant Bit_Index := 1 + Register_A * Storage_Unit; Bit_A3 : constant Bit_Index := 7 + Register_A * Storage_Unit; Register_B : constant Address_Type := 1; Bit_B1 : constant Bit_Index := 4 + Register_B * Storage_Unit; Bit_B2 : constant Bit_Index := 2 + Register_B * Storage_Unit; Bit_B3 : constant Bit_Index := 5 + Register_B * Storage_Unit; Register_Z : constant Address_Type := 25; Bit_Z1 : constant Bit_Index := 6 + Register_Z * Storage_Unit; Bit_Z2 : constant Bit_Index := 0 + Register_Z * Storage_Unit; Bit_Z3 : constant Bit_Index := 5 + Register_Z * Storage_Unit; procedure Set_Bit (Regs : in Registers; Idx : in Bit_Index); procedure Clear_Bit (Regs : in Registers; Idx : in Bit_Index); Once all of the Bit_Index constants are correctly declared, they contain within their values the register number as well. This also simplifies the Set and Clear procedures, as well, because the specific bit is accessed simply as Regs (Idx) ----- Original Message ----- From: "Bernd Trog" Newsgroups: comp.lang.ada,comp.arch.embedded To: Sent: February 17, 2003 6:06 PM Subject: Type-safe low-level programming? > Hi, > lets say I've something like this: > > pragma No_Run_Time; > > type Bit_Number is range 0 .. 7; > type Address_Type is range 0 .. 16#ff#; > > Register_A : constant Address_Type := 1; > Bit_A1 : constant Bit_Number := 4; --Register A, Bit 4 > Bit_A2 : constant Bit_Number := 1; > Bit_A3 : constant Bit_Number := 7; > > Register_B : constant Address_Type = 2; > Bit_B1 : constant Bit_Number :=4; > Bit_B2 : constant Bit_Number :=2; > Bit_B3 : constant Bit_Number :=5; > [...] > Register_Z : constant Address_Type = 2; > Bit_Z1 : constant Bit_Number :=6; > Bit_Z2 : constant Bit_Number :=0; > Bit_Z3 : constant Bit_Number :=5; > > procedure Set_Bit( Adr : in Address_Type; Nr : in Bit_Number ); > procedure Clear_Bit( Adr : in Address_Type; Nr : in Bit_Number ); > > On a not-so-good day I wrote: > Set_Bit( Register_A, Bit_B3 ); > and found my error days later :-( > > Now I wonder, if its possible to make 'Set_Bit' type-safe *without* > increasing the program memory size for every new register? > > > Bernd > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada.eu.org > http://ada.eu.org/mailman/listinfo/comp.lang.ada > >