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: f849b,869d7890f1bd9878 X-Google-Attributes: gidf849b,public X-Google-Thread: 103376,869d7890f1bd9878 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-18 06:53:59 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!12.120.28.37.MISMATCH!attla2!ip.att.net!attbi_feed3!attbi.com!rwcrnsc54.POSTED!not-for-mail From: "Steve" Newsgroups: comp.lang.ada,comp.arch.embedded References: Subject: Re: Type-safe low-level programming? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: <8Or4a.165295$vm2.120896@rwcrnsc54> NNTP-Posting-Host: 12.211.13.75 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc54 1045580036 12.211.13.75 (Tue, 18 Feb 2003 14:53:56 GMT) NNTP-Posting-Date: Tue, 18 Feb 2003 14:53:56 GMT Organization: AT&T Broadband Date: Tue, 18 Feb 2003 14:53:56 GMT Xref: archiver1.google.com comp.lang.ada:34195 comp.arch.embedded:59728 Date: 2003-02-18T14:53:56+00:00 List-Id: Here is one way to get there: TYPE Bit_Number IS RANGE 0 .. 7; TYPE Address_Type IS RANGE 0 .. 16#ff#; TYPE Reg_A_Bit_Number IS NEW Bit_Number; TYPE Reg_B_Bit_Number IS NEW Bit_Number; TYPE Reg_Z_Bit_Number IS NEW Bit_Number; TYPE Reg_A_Address_Type IS NEW Address_Type; TYPE Reg_B_Address_Type IS NEW Address_Type; TYPE Reg_Z_Address_Type IS NEW Address_Type; Register_A : CONSTANT Reg_A_Address_Type := 1; Bit_A1 : CONSTANT Reg_A_Bit_Number := 4; --Register A, Bit 4 Bit_A2 : CONSTANT Reg_A_Bit_Number := 1; Bit_A3 : CONSTANT Reg_A_Bit_Number := 7; Register_B : CONSTANT Reg_B_Address_Type := 2; Bit_B1 : CONSTANT Reg_B_Bit_Number :=4; Bit_B2 : CONSTANT Reg_B_Bit_Number :=2; Bit_B3 : CONSTANT Reg_B_Bit_Number :=5; Register_Z : CONSTANT Reg_Z_Address_Type := 2; Bit_Z1 : CONSTANT Reg_Z_Bit_Number :=6; Bit_Z2 : CONSTANT Reg_Z_Bit_Number :=0; Bit_Z3 : CONSTANT Reg_Z_Bit_Number :=5; PROCEDURE Set_Bit_Exp( Adr : IN Address_Type; Nr : IN Bit_Number ); PRAGMA Export( Ada, Set_Bit_Exp, "Set_Bit_Exp" ); PROCEDURE Clear_Bit_Exp( Adr : IN Address_Type; Nr : IN Bit_Number ); PRAGMA Export( Ada, Clear_Bit_Exp, "Clear_Bit_Exp" ); PROCEDURE Set_Bit( Adr : IN Reg_A_Address_Type; Nr : IN Reg_A_Bit_Number ); PROCEDURE Set_Bit( Adr : IN Reg_B_Address_Type; Nr : IN Reg_B_Bit_Number ); PROCEDURE Set_Bit( Adr : IN Reg_Z_Address_Type; Nr : IN Reg_Z_Bit_Number ); PRAGMA Import( Ada, Set_Bit, "Set_Bit_Exp" ); PROCEDURE Clear_Bit( Adr : IN Reg_A_Address_Type; Nr : IN Reg_A_Bit_Number ); PROCEDURE Clear_Bit( Adr : IN Reg_B_Address_Type; Nr : IN Reg_B_Bit_Number ); PROCEDURE Clear_Bit( Adr : IN Reg_Z_Address_Type; Nr : IN Reg_Z_Bit_Number ); PRAGMA Import( Ada, Clear_Bit, "Clear_Bit_Exp" ); Using the export and import clauses only one instance of Set_Bit_Exp and Clear_Bit_Exp are created. This is a bit of a "trick" to have type checking while not having type checking (if you know what I mean). You could also try defining the different types as shown as well as separate instances of the routines, only define them all as in-line. I suspect the complexity of your Set_Bit and Clear_Bit functions would be so simple that in-line code would not increase the size. You could also try creating the routines as generic, with a different instance for each type. Some compilers would share code. Steve (The Duck) "Bernd Trog" wrote in message news:cbdd91ae.0302171606.57d2ba77@posting.google.com... > Hi, > lets say I've something like this: > > pragma No_Run_Time; [snip] > 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